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
class Vec2 {
x;
y;
constructor(x, y) {
this.x = x;
this.y = y;
}
distanceTo(other) {
return Math.sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2);
}
}
function update(bufferA, bufferB) {
for (let x = 0;x < bufferA.length; ++x) {
bufferB[x].x = 0;
bufferB[x].y = 0;
for (let y = 0;y < bufferA.length; ++y) {
if (x === y) {
continue;
}
const f = 1 / bufferA[x].distanceTo(bufferA[y]) ** 2;
bufferB[x].x += (bufferA[x].x - bufferA[y].x) * f;
bufferB[x].y += (bufferA[x].y - bufferA[y].y) * f;
}
bufferB[x].x = bufferA[x].x + bufferB[x].x;
bufferB[x].y = bufferA[x].y + bufferB[x].y;
}
}
function work(size) {
let bufferA = [];
let bufferB = [];
for (let i = 0;i < size; ++i) {
bufferA.push(new Vec2(Math.random() - 0.5, Math.random() - 0.5));
bufferB.push(new Vec2(0, 0));
}
for (let iteration = 0;iteration < 128; ++iteration) {
update(bufferA, bufferB);
const tmp = bufferA;
bufferA = bufferB;
bufferB = tmp;
}
console.log(bufferA[0].x);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
work1 |
| ready |
work10 |
| ready |
work100 |
| ready |
work1000 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.