Last active
August 29, 2015 14:28
-
-
Save brendanashworth/71e332481f5e1e525a90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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