Map/for loop perf (10) (v2)

Revision 2 of this benchmark created on


Setup

const count = 10;
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.