For loop test (v8)

Revision 8 of this benchmark created on


Setup

const LENGTH = 1_000_000;
const target = Array.from({length: LENGTH}, () => Math.floor(Math.random() * LENGTH));

Test runner

Ready to run.

Testing in
TestOps/sec
classic
for (let i = 0; i < target.length; i++) {
	target[i]**2;
}
ready
forEach
target.forEach(n => {n**2});
ready
for..of
for (const num of target) {
	num**2;
}
ready
map
target.map(n=>{
	n**2
})
ready
reduce
target.reduce((_, __, i, arr) => {
    arr[i] = i ** 2;
    return null;
}, null);
ready
do....while
i = 0;
do {
    target[i] = i ** 2;
    i++;
} while (i < target.length);
ready
while
let i = 0;
while (i < target.length) {
    target[i] = i ** 2;
    i++;
}
ready
for....in....
for (const i in target) {
    target[i] = i ** 2;
}
ready
map
target.map((_, i) => {
    return i ** 2;
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.