Skip to content

Instantly share code, notes, and snippets.

@smarden1
Created May 18, 2015 17:40
Show Gist options
  • Save smarden1/2cebe6eb07e964c8088b to your computer and use it in GitHub Desktop.
Save smarden1/2cebe6eb07e964c8088b to your computer and use it in GitHub Desktop.
var NanoTimer = require('nanotimer');
var timing = new NanoTimer();
d = {};
i = 10000;
while (i > 0) {
d[i] = true;
i --;
}
oldf = function(d) {
var values = [];
for (var value in d) {
values.push(value);
}
return d.length;
}
newf = function(d) {
return Object.keys(d).length;
}
run_many_times = function(fn) {
return function() {
var i = 1000;
while (i > 0) {
fn(d);
i--;
}
}
}
console.log("timing started...")
var microsecs = timing.time(run_many_times(oldf));
console.log("old:");
console.log(microsecs);
var microsecs = timing.time(run_many_times(newf));
console.log("new:");
console.log(microsecs);
st-smardenfeld1:statsd_smarden1 smardenfeld$ node ./set_timing.js
timing started...
old:
[ 0, 904347709 ]
new:
[ 0, 347407343 ]
st-smardenfeld1:statsd_smarden1 smardenfeld$ node ./set_timing.js
timing started...
old:
[ 0, 834463074 ]
new:
[ 0, 367127422 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment