Created
April 27, 2016 23:15
-
-
Save paulstatezny/a2d2150a6743787ce96decca4c7c40af to your computer and use it in GitHub Desktop.
Benchmarking how much faster it is to null a property of a complex object versus deleting that property in JavaScript
This file contains hidden or 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 Benchmark = require('benchmark'); | |
function complete() { | |
console.log(String(this)); | |
} | |
var objDeleteBenchmark = new Benchmark('Object#delete-property', { | |
setup: function() { | |
var obj = { | |
foo: { | |
bar: { | |
baz: 'baz', | |
qux: 'qux', | |
bool: false | |
} | |
}, | |
foo2: { | |
bar2: { | |
baz: false | |
} | |
} | |
}; | |
}, | |
fn: function() { delete obj.foo.bar; } | |
}); | |
var nullPropertyBenchmark = new Benchmark('Object#null-property', { | |
setup: function() { | |
var obj = { | |
foo: { | |
bar: { | |
baz: 'baz', | |
qux: 'qux', | |
bool: false | |
} | |
}, | |
foo2: { | |
bar2: { | |
baz: false | |
} | |
} | |
}; | |
}, | |
fn: function() { obj.foo.bar = null; } | |
}); | |
objDeleteBenchmark.run({ 'async': true }).on('complete', complete); | |
nullPropertyBenchmark.run({ 'async': true }).on('complete', complete); |
Author
paulstatezny
commented
Apr 27, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment