| OLD | NEW |
| (Empty) | |
| 1 define([ ], function () { |
| 2 // Benchmarks fn until maxTime ms has passed. Returns approximate number |
| 3 // of operations performed in that time ('score'). |
| 4 function bench(maxTime, fn) { |
| 5 if (typeof fn !== 'function') { |
| 6 throw new TypeError('Argument must be a function'); |
| 7 } |
| 8 |
| 9 var operationCount = 0; |
| 10 var startTime = Date.now(); |
| 11 var endTime; |
| 12 while (true) { |
| 13 fn(operationCount); |
| 14 ++operationCount; |
| 15 |
| 16 endTime = Date.now(); |
| 17 if (endTime - startTime >= maxTime) { |
| 18 break; |
| 19 } |
| 20 } |
| 21 |
| 22 return operationCount / (endTime - startTime) * maxTime; |
| 23 } |
| 24 |
| 25 return bench; |
| 26 }); |
| OLD | NEW |