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
Tests to benchamark data locality between arrays, map entries, map keys, map values, object entries, object values. This is used to determine best approach for iterations.
const SIZE = 10_000;
const objectsArray= [];
const instancesArray= [];
const mapWithIntKey = new Map();
const mapWithStrKey = new Map();
var sum = 0;
class Point {
constructor(a, b) {
this.a = a;
this.b = b;
this.r = 0;
this.idCopy = 0;
}
operate() {
this.r = this.a + this.b;
return this.r;
}
copyId(newId) {
this.idCopy = newId;
}
}
for (let i = 0; i < SIZE; i++) {
/*Use random IDs to avoid backing up by arays*/
const id = i + Date.now();
const a = getRandomInt(SIZE);
const b = getRandomInt(SIZE);
const obj = {id: id, a:a, b:b, r:0, idCopy: 0};
objectsArray.push(obj);
mapWithIntKey.set(id, obj);
mapWithStrKey.set('a' + id, obj);
const point = new Point(a, b);
instancesArray.push(point);
}
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Test class instances |
| ready |
Map with integer key: test entries performance |
| ready |
Array for: const in loop |
| ready |
Map with string key: test entries performance |
| ready |
Map with integer key: test values performance |
| ready |
Map with string key: test values performance |
| ready |
Array for: var outside loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.