Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created March 26, 2010 14:53
Show Gist options
  • Save aheckmann/344975 to your computer and use it in GitHub Desktop.
Save aheckmann/344975 to your computer and use it in GitHub Desktop.
var sys = require('sys');
var uuid = function() {
var uuid = '', i;
for (i = 0; i < 32; i++) {
uuid += Math.floor(Math.random() * 16).toString(16);
}
return uuid;
};
var a = {}, u, index=[];
for( var i = 0; i < 1000000; ++i) {
u = uuid();
a[u] = {id: "asdfasdfasda"};
index[index.length] = u;
}
var start = (new Date).getTime(), key;
for(key in a) {
a[key];
}
sys.puts("for key in loop: " + ((new Date).getTime() - start));
var start = (new Date).getTime(), keys = Object.keys(a), len = keys.length;
while(--len) {
a[keys[len]];
}
sys.puts("while loop with keys: " + ((new Date).getTime() - start));
var start = (new Date).getTime(), len = index.length
while(--len) {
a[index[len]];
}
sys.puts("while loop with index: " + ((new Date).getTime() - start));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment