Map/for loop perf

Benchmark created on


Setup

const count = 1000;
const data = new Array(count);
for (let i = 0; i < count; i++) {
	data[i] = i
}

Test runner

Ready to run.

Testing in
TestOps/sec
map
const results = data.map((item) => {
	return item * 1000
})
ready
for with push
const results = []
for (let i = 0; i < data.length; i++) {
	results.push(data[i] * 1000)
}
ready
for with pre-allocated array
const results = new Array(data.length)
for (let i = 0; i < data.length; i++) {
	results[i] = data[i] * 1000
}
ready
for of
const results = []
for (const item of data) {
	results.push(item * 1000)
}
ready

Revisions

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