Last active
January 25, 2018 12:29
-
-
Save davedx/ee913e07c198c35bb96df5700fea37bd 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
let cache1 = {}, cache2 = {} | |
const blob = () => { | |
var d = [] | |
for (var i=0; i<10; i++) { | |
d[i] = Math.random() | |
} | |
return d | |
} | |
let its = 100000 | |
console.log('iterations: '+its) | |
for (var i=0; i<its; i++) { | |
const idx = `key_${i}` | |
cache1[idx] = blob() | |
cache2[idx] = blob() | |
} | |
// now let's time deletions | |
let t1 = Date.now() | |
for (var i=0; i<its; i++) { | |
delete cache1[`key_${i}`] | |
} | |
console.log(`delete time: ${Date.now()-t1} = ${(Date.now()-t1)/its} ms/op`) | |
let t2 = Date.now() | |
for (var i=0; i<its; i++) { | |
cache2[`key_${i}`] = null | |
} | |
console.log(`null time: ${Date.now()-t2} = ${(Date.now()-t2)/its} ms/op`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
root@3C36E4-EOSSTB-003471180509:/usr/lib/node_modules/visual-tests# node test
iterations: 10000
delete time: 22 = 0.0022 ms/op
null time: 34 = 0.0034 ms/op
root@3C36E4-EOSSTB-003471180509:/usr/lib/node_modules/visual-tests# node test
iterations: 50000
delete time: 225 = 0.0045 ms/op
null time: 301 = 0.00602 ms/op
root@3C36E4-EOSSTB-003471180509:/usr/lib/node_modules/visual-tests# node test
iterations: 100000
delete time: 467 = 0.00467 ms/op
null time: 629 = 0.00629 ms/op
root@3C36E4-EOSSTB-003471180509:/usr/lib/node_modules/visual-tests#