Created
November 21, 2012 17:03
-
-
Save caridy/4126067 to your computer and use it in GitHub Desktop.
Compare set to null vs delete member in NodeJS
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
NodeJS 0.8.x on MBP: | |
$ node delete.js | |
89300 'value to null' | |
3100674 'deleting member' |
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 microtime = require('microtime'), | |
i, | |
t, | |
obj, | |
max = 10000000; | |
function run1(obj) { | |
obj.foo = null; // seeting value to falsy | |
t = microtime.now(); | |
for (i = 0; i < max; i += 1) { | |
if (obj.foo) { | |
obj.foo(); | |
} | |
} | |
console.log(microtime.now() - t, 'value to null'); | |
} | |
function run2(obj) { | |
delete obj.foo; // deleting member | |
t = microtime.now(); | |
for (i = 0; i < max; i += 1) { | |
if (obj.foo) { | |
obj.foo(); | |
} | |
} | |
console.log(microtime.now() - t, 'deleting member'); | |
} | |
run1({ | |
foo: function () { | |
var f = 1; | |
}, | |
bar: 1 | |
}); | |
run2({ | |
foo: function () { | |
var f = 1; | |
}, | |
bar: 1 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment