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
Which is faster?
const objs = [];
for (let i = 0; i < 100_000; i++) {
const n = Math.floor(1 + Math.random() * 10);
objs.push({n});
}
window.trash = 0;
function handle1(obj) {
window.trash += obj.n;
}
function handle2(obj) {
window.trash *= obj.n;
}
function handle3(obj) {
window.trash /= (obj.n + 1);
}
function handle4(obj) {
window.trash -= obj.n;
}
function handle5(obj) {
window.trash = obj.n >> 1;
}
function handle6(obj) {
window.trash = obj.n >> 2;
}
function handle7(obj) {
window.trash = obj.n >> 3;
}
function handle8(obj) {
window.trash = obj.n >> 4;
}
function handle9(obj) {
window.trash = obj.n >> 5;
}
function handle10(obj) {
window.trash = obj.n >> 6;
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| switch statement | | ready |
| if statement | | ready |
| object hash | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.