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
const map = new Map(Array.from({ length: 10000 }, (_, val) => [val + 1, val + 1]))
const target = 9112
function forOf(map, target) {
for (const [val] of map) {
if (val === target) {
return val
}
}
}
function forOfKeys(map, target) {
for (const val of map.keys()) {
if (val === target) {
return val
}
}
}
function forOfValues(map, target) {
for (const val of map.values()) {
if (val === target) {
return val
}
}
}
function forArr(map, target) {
const arr = Array.from(map)
for (let i = arr.length - 1; i >= 0; --i) {
if (arr[i][0] === target) {
return arr[i][0]
}
}
}
function forOfArr(map, target) {
for (const [val] of Array.from(map)) {
if (val === target) {
return val
}
}
}
function forEach(map, target) {
map.forEach((_, val) => {
if (val === target) {
return val
}
})
}
function forValues(map, target) {
for (let it = map.values(), val = null; val = it.next().value;) {
if (val === target) {
return val
}
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
for-of |
| ready |
for-reversed |
| ready |
array for-of |
| ready |
forEach |
| ready |
forOfKeys |
| ready |
values iterator |
| ready |
forOfValues |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.