Last active
April 26, 2016 11:36
-
-
Save yadimon/c68e807d96760c713ba35300ba92e423 to your computer and use it in GitHub Desktop.
measure execution time of function (mini benchmark) in promises in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//perf start | |
var lastCallName = ''; | |
function timePromise(name) { | |
var lastNameToEnd = lastCallName ? lastCallName : ''; | |
lastCallName = name; | |
return function (data) { | |
if (lastNameToEnd) console.timeEnd(lastNameToEnd); | |
console.time(name); | |
return data; | |
}; | |
} | |
//perf end | |
//your code | |
do1Promise() | |
.then(do2Promise) | |
.then(function(result){return do3Promise(result+1)}); | |
//your code with time of execution | |
Promise.resolve() | |
.then(timePromise('do1Promise')) | |
.then(function(){return do1Promise()}) | |
.then(timePromise('do2Promise')) | |
.then(do2Promise) | |
.then(timePromise('do3Promise')) | |
.then(function(result){return do3Promise(result+1)}) | |
.then(timePromise('end it all')); //todo fix end call | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment