Created
December 5, 2012 18:09
-
-
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)
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 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