Skip to content

Instantly share code, notes, and snippets.

@aotimme
Created December 5, 2012 18:09
Show Gist options
  • Save aotimme/4218043 to your computer and use it in GitHub Desktop.
Save aotimme/4218043 to your computer and use it in GitHub Desktop.
Quick example test of how object is implemented in node and chrome. (Hint: it's a hash table)
var i;
var MAX = 100000;
/* === Versions ===
* NODE: v0.6.12
* CHROME: 23.0.1271.64
*/
/* === Hash ===
* NODE: 12ms
* CHROME: 187.885ms
*/
console.time('hash');
var hash = {};
for (i = 0; i < MAX; i++) {
if (hash[i] == null) {
hash[i] = true;
}
};
console.timeEnd('hash');
/* === Array ===
* NODE: 10879ms
* CHROME: 23840.928ms
*/
console.time('arr');
var arr = [];
for (i = 0; i < MAX; i++) {
if (arr.indexOf(i) === -1) {
arr.push(i);
}
};
console.timeEnd('arr');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment