aboutsummaryrefslogtreecommitdiffstats
path: root/speed/benchmark.js
blob: 364d7dd35d1174555397b8e4a7b08b8110c51e52 (plain)
1
// 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);
}