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
Compares performance of a map vs an object.
In both cases, the map and object are largs, with large amounts of properties added to them. This simulates an object that might be used as a lookup table.
function createLargeObject() {
let OBJ = { "string": 1 };
for(let i = 0; i < 4; i++) {
for(let j = 0; j < 200; j++) {
let R = (Math.random() * 100).toString();
OBJ[R] = R;
}
}
return OBJ;
}
function createLargeObjectWithSpread() {
let OBJ = { "string": 1 };
for(let i = 0; i < 4; i++) {
for(let j = 0; j < 200; j++) {
let R = (Math.random() * 100).toString();
OBJ[R] = R;
}
}
return {...OBJ};
}
function createLargeMap() {
let MAP = new Map([["string", 1]]);
for(let i = 0; i < 4; i++) {
for(let j = 0; j < 200; j++) {
let R = (Math.random() * 100).toString();
MAP.set(R, R);
}
}
return MAP;
}
var OBJ = createLargeObject();
var MAP = createLargeMap();
var SPREADOBJ = createLargeObjectWithSpread();
var RESULT;
Ready to run.
Test | Ops/sec | |
---|---|---|
Get (Object) |
| ready |
Get (Map) |
| ready |
Get (SpreadObject) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.