ruk·si

🍦 JavaScript
Benchmarking

Updated at 2015-05-14 19:38
// TODO: create async version.
var benchmarkSync = function(target, times) {
  var start = Date.now();
  for (var i = 0; i < times; i++) {
    target();
  }
  return (Date.now() - start) / times;
}

var functionUnderTest = function() {
    for (var i = 0; i < 100; ++i) {
      var x = i + i;
    }
};

var howLongSingleCallTook = benchmarkSync(functionUnderTest, 1000000);

console.log(howLongSingleCallTook);