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