Skip to content

Instantly share code, notes, and snippets.

@brendanashworth
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanashworth/71e332481f5e1e525a90 to your computer and use it in GitHub Desktop.
Save brendanashworth/71e332481f5e1e525a90 to your computer and use it in GitHub Desktop.
// Simple one-function benchmark for node.js
// originally from http://mrale.ph/blog/2011/03/30/external-arrays-and-nodejs.html
// Pass n = number of iterations (only affects accuracy of ns/op)
// Pass f = function to call
function benchmark(n, f) {
var start = process.hrtime();
for (var i = 0; i < n; i++) f();
var end = process.hrtime(start);
console.log("took %s ns / op", ((end[0] * 1e9) + end[1]) / n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment