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
let options = ["id","class","pseudo","tag","attribute"];
function makeItem() {
return {
type: options[Math.floor(Math.random() * 4.99999)]
};
}
let smallInput = (new Array(10)).fill().map(makeItem);
let largeInput = (new Array(40000)).fill().map(makeItem);
function sortForEach(selectors) {
let sorted = { tag: [], id: [], class: [], attribute: [], pseudo: [] };
selectors.forEach((selector, i) => {
sorted[selector.type].push(i);
});
return [ ... sorted.pseudo, ... sorted.tag, ... sorted.attribute, ... sorted.class, ... sorted.id ];
}
function sortFor(selectors) {
let sorted = { tag: [], id: [], class: [], attribute: [], pseudo: [] };
for (let i = 0; i < selectors.length; i++) {
sorted[selectors[i].type].push(i);
}
return [ ... sorted.pseudo, ... sorted.tag, ... sorted.attribute, ... sorted.class, ... sorted.id ];
}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| forEach (small) | | ready |
| for loop (small) | | ready |
| forEach (large) | | ready |
| for loop (large) | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.