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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function* source(array) {
for (let i = 0; i < array.length; i++) {
yield array[i];
}
}
// Function 1: for...of loop
function forOfLoop(arr) {
let sum = 0;
for (const num of arr) {
sum += num;
}
return sum;
}
// Function 2: while loop using [Symbol.iterator]
function whileLoopIterator(arr) {
let sum = 0;
const iterator = arr[Symbol.iterator]();
let result = iterator.next();
while (!result.done) {
sum += result.value;
result = iterator.next();
}
return sum;
}
function arrayFromFor(gen) {
const arr = Array.from(gen);
let sum = 0;
for (let i = 0; i<arr.length; i++) {
sum += arr[i];
}
return sum;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
for of |
| ready |
while |
| ready |
arrayFromFor |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.