Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
9 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
@@ -1 +1,9 @@ | ||
// Runs a function many times without the function call overheadfunction benchmark(fn, times){ fn = fn.toString() var s = fn.indexOf('{')+1, e = fn.lastIndexOf('}'); fn = fn.substring(s,e); return new Function('i','var t=new Date;while(i--){'+fn+'};return new Date-t')(times);} | ||
// Runs a function many times without the function call overhead | ||
function benchmark(fn, times){ | ||
fn = fn.toString(); | ||
var s = fn.indexOf('{')+1, | ||
e = fn.lastIndexOf('}'); | ||
fn = fn.substring(s,e); | ||
|
||
return new Function('i','var t=new Date;while(i--){'+fn+'};return new Date-t')(times); | ||
} |