jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Given an object that comes in:
<span class="kw2">var</span> map <span class="sy0">=</span> <span class="br0">{</span> <span class="st0">'key'</span><span class="sy0">:</span> <span class="st0">'value'</span><span class="sy0">,</span> ... <span class="br0">}</span><span class="sy0">;</span>
How expensive is it to iterate over the keys using different techniques?
// Hardcoded map of 9 keys. It's not mutated. This roughly matches the intended use case.
var map = { a: 1, b: '2', c: null, d: [4], e: {f: 56}, g: 7, h: 8, i: 9, j: 10 };
var cachedKeys = Object.keys(map);
// The number of keys with truthy values
var expectedCount = 8;
Ready to run.
Test | Ops/sec | |
---|---|---|
for-in to enumerate keys |
| ready |
Object.keys |
| ready |
cached keys |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.