Tagging the 1.5rc1 release.
[jquery.git] / speed / benchmark.js
1 // Runs a function many times without the function call overhead
2 function benchmark(fn, times, name){
3         fn = fn.toString();
4         var s = fn.indexOf('{')+1,
5                 e = fn.lastIndexOf('}');
6         fn = fn.substring(s,e);
7         
8   return benchmarkString(fn, times, name);
9 }
10
11 function benchmarkString(fn, times, name) {
12   var fn = new Function("i", "var t=new Date; while(i--) {" + fn + "}; return new Date - t")(times)
13   fn.displayName = name || "benchmarked";
14   return fn;
15 }