Skip to content

Instantly share code, notes, and snippets.

@kiichi
Created December 26, 2014 18:44
Show Gist options
  • Save kiichi/cd7a959b2cc2da223363 to your computer and use it in GitHub Desktop.
Save kiichi/cd7a959b2cc2da223363 to your computer and use it in GitHub Desktop.
JavaScript Benchmark Function
//--------------------------------------------------------------------------------------------------
// show benchmark result of function
// e.g. benchMe(heavyFunc,null,5)
function benchMe(myFunc, myArgs, cnt){
if (!cnt || cnt <= 0){
cnt = 1;
}
var startTime = (new Date()).getTime();
for (var i=0; i<cnt; i++){
myFunc(myArgs);
}
return (((new Date()).getTime()-startTime)/cnt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment