Push vs allocate vs map

Benchmark created on


Setup

let array = [0,1,2,3,4,5,6,7,8,9,10]
let empty_array = []

function foo(a) {
	return a
}

Test runner

Ready to run.

Testing in
TestOps/sec
Push
let a = []

for(let i = 0; i < array.length; ++i)
 {
 	a.push( foo(array[i]) )
 }
ready
Allocate
let a = new Array(array.length)

for(let i = 0; i < array.length; ++i)
 {
 	a[i] = foo(array[i])
 }
ready
Map
let a = array.map(foo)
ready

Revisions

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