Check for property in advance or handle not having got it
JavaScript performance comparison
Info
Check for a property before retrieving it vs. retrieving it and then seeing if it's falsey
Preparation code
<script>
Benchmark.prototype.setup = function() {
var o = (function() {
var counter = 100,
o = {};
while (counter-- > 0) {
if (counter !== 6) {
o[counter] = [counter]; // Note we're storing an array
}
}
return o;
})();
var foundKey = 5;
var unFoundKey = 6;
var entry;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Check first |
|
pending… |
Get it and then test |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments