Skip to content
Permalink
Browse files

Reformat benchamrk function.

  • Loading branch information
jeresig committed Feb 5, 2010
1 parent be2407e commit 5d2e0efd7c23132a7f3a3b34ae3b8058413c1b61
Showing with 9 additions and 1 deletion.
  1. +9 −1 speed/benchmark.js
@@ -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);
}

0 comments on commit 5d2e0ef

Please sign in to comment.
You can’t perform that action at this time.