Created
October 15, 2020 06:04
-
-
Save wilf312/4885d8ff9f62049993bf505ce388eecf to your computer and use it in GitHub Desktop.
JS set vs obj performance
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 N = 100000000 | |
var theSet = new Set(); | |
console.time() | |
/***********************************/ | |
for(let i = 0 ; i < N; i++ ) { | |
let v = i%20; | |
if (!theSet.has(v)) | |
theSet.add(v); | |
} | |
/***********************************/ | |
console.timeEnd() | |
console.log('section 1 : '); | |
obj = {}; | |
console.time() | |
/***********************************/ | |
for(let i = 0 ; i < N; i++) { | |
let v = i%20; | |
if (!obj[v]) | |
obj[v] = 1; | |
} | |
/***********************************/ | |
console.timeEnd() | |
console.log('section 2 : '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment