blob: 8f1aa985a18cecbae44616c939cc81c2c23fd423 (
plain)
1
2
3
4
5
6
7
8
9
|
// 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);
}
|