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