Is there a way to reliably query an SQL query in Node.js or any other type of function?

I am trying to wrap my head with aysnc functions in node. This is a good way to find out how long a database query has been running to work through node.js.

For the application used, the time required to complete the set of algorithms is used. I take the input from one and connect it to the other. Tweaks to the first set can output more or less data. therefore, measuring the response of the total time may not be very accurate. I am trying to measure the runtime of each function.

any pointers * regarding the theory would appreciate an attempt to study the concept, I think it is important !.

+3
source share
1 answer

In the context of synchronization, you should do the following:

 var time = function(fn){
   var start = Date.now();
   fn();
   return start - Date.now()
 }
 // which would be called this way : 
 var elapsed = time(function(){
   // do something
 }
 // do something with elapsed
 // do something else

:

 var time = function(fn, cb){
    var start = Date.now();
    fn(null, function(){
      var args = [].slice.call(arguments);
      args.splice(1, 0, Date.now() - start);
      cb.apply(this,args); 
    })
 }
 // which you would use this way: 
 time(function(err, cb){
   // do something
   cb(/* params */);
 }, function(err, elapsed /*, params */){
   // do something with elapsed
   // do something else
 });

, , ( ).

+6

All Articles