Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created March 12, 2014 15:24
Show Gist options
  • Save mraleph/9509144 to your computer and use it in GitHub Desktop.
Save mraleph/9509144 to your computer and use it in GitHub Desktop.
function GeneratedBenchmarkingFunction() {
/* Benchmark.prototype.setup goes here */
var start = new Date;
for (...) { /* do N iterations of test body */
/* test case goes here */
}
var end = new Date;
/* Benchmark.prototype.teardown goes here */
/* N / (end - start) gives ops per ms result */
};
@safjanowski
Copy link

function GeneratedBenchmarkingFunction(fun) {
  var start = (new Date).getTime();
  for (...) { /* do N iterations of test body */
    fun();
  }
  var end = (new Date).getTime();
  console.log(fun.name, ':', (new Date()).getTime() - start);
};

@mraleph
Copy link
Author

mraleph commented Mar 12, 2014

function GeneratedBenchmarkingFunction() {
  var start = new Date;
  for (...) { /* do N iterations of test body */
function matchRegexp() {
  var r = new RegExp(/^((auto)|\d+[a-z]*)$/);
  'auto'.match(r);
  '10px'.match(r);
  'Lorem ipsum dolor sit amet'.match(r);
}
  }
  var end = new Date;
  /* Benchmark.prototype.teardown goes here */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment