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
Testing the performance differences between a for loop with an if condition, and filter, mapping over.
We will generate an array with a million entries that are numbers between 0 and 100. We will then ignore any number below 25, and return all numbers above.
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Create an empty array
const largeArray = [];
// Generate and push 1,000,000 random numbers into the array
for (let i = 0; i < 10000; i++) {
const randomNumber = getRandomNumber(1, 100); // Generate a random number between 1 and 100
largeArray.push({num, randomField: true});
}
Ready to run.
Test | Ops/sec | |
---|---|---|
For Loop |
| ready |
Filter...Map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.