Created
May 18, 2015 17:40
-
-
Save smarden1/2cebe6eb07e964c8088b 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
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); |
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
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