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)*(this.x - other.x) + (this.y - other.y)*(this.y - other.y));
}
}
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) {
const bufferA = new Array(size);
const bufferB = Array.from(bufferA);
for (let i = 0;i < size; ++i) {
bufferA[i] = new Vec2(Math.random() - 0.5, Math.random() - 0.5);
bufferB[i] = new Vec2(0, 0);
}
for (let iteration = 0;iteration < 128; iteration+=2) {
update(bufferA, bufferB);
update(bufferB, bufferA);
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
work1000 |
| ready |
work100 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.