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 existingArraySize = 1
const searchedArraySize = 100
// Shuffle is not in std lib :(
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
// Used to verify that we have the correct result
function assertResult(result) {
if (result.length !== searchedArraySize - existingArraySize) throw new Error(`${result.length} is invalid length! Expected: ${searchedArraySize - existingArraySize}`)
}
// Prepare alpha array with random order
var alpha = shuffleArray(new Array(searchedArraySize).fill(null).map((_,i) => 10000+i))
// Pick few random values from the array as existing array (we assume the existing array always have matches in the original)
var existingValues = shuffleArray([...alpha]).slice(0, existingArraySize)
// Create helper structures
var existing = new Set(existingValues)
var existingMap = new Map(existingValues.map(v => [v,true]))
var existingObject = Object.fromEntries(existingValues.map(v => [v, true]))
Ready to run.
Test | Ops/sec | |
---|---|---|
Filter and has |
| ready |
Loop and plain object |
| ready |
Loop and some |
| ready |
Loop and Set.has |
| ready |
Loop and Map.has |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.