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
Compare reading performance of native Map implementation vs using an object as a hash map.
var map = new Map();
var obj = {};
var hashSize = 1000000;
var testKeyNum = 20;
var testkeys = [];
for (var i = 0; i < hashSize; i++) {
var key = randomString();
var val = randomString();
map.set(key, val);
obj[key] = val;
}
var keys = Array.from(map.keys());
for (var i = 0; i < testKeyNum; i++) {
var testkey = keys[Math.random()*hashSize >>> 0];
testkeys.push(testkey);
}
function randomString() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
map.get(key) |
| ready |
obj[key] |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.