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
Array approach: Pros:
Weak Set approach: Pros:
const myList = [];
const myListLarge = [];
const mySet = new WeakSet();
const entries = [];
let index = 0;
let indexLarge = 0;
function addToMyList(element) {
mySet.add(element);
if(myList.length == 20) {
myList[index++] = element;
index %= 20;
} else {
myList.push(element);
}
if(myListLarge.length == 50) {
myListLarge[indexLarge++] = element;
indexLarge %= 20;
} else {
myListLarge.push(element);
}
}
function queryList(element) {
return myList.includes(element);
}
function queryListLarge(element) {
return myListLarge.includes(element);
}
function querySet(element) {
return mySet.has(element);
}
for(let i = 0; i < 100; i++) {
entries[i] = {
id: i
};
if(i < 50) {
addToMyList(entries[i]);
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Array |
| ready |
Weak Set |
| ready |
Array (Large) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.