Skip to content

Instantly share code, notes, and snippets.

@davedx
Last active January 25, 2018 12:29
Show Gist options
  • Save davedx/ee913e07c198c35bb96df5700fea37bd to your computer and use it in GitHub Desktop.
Save davedx/ee913e07c198c35bb96df5700fea37bd to your computer and use it in GitHub Desktop.
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`)
@davedx
Copy link
Author

davedx commented Jan 25, 2018

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#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment