array replacement vs emplace

Benchmark created on


Setup

let array = [0,0,0];

function replace(x, y, z) {
	array = [x, y, z];
}

function emplace(array, x, y, z) {
	array[0] = x;
	array[1] = y;
	array[2] = z;
}

Test runner

Ready to run.

Testing in
TestOps/sec
direct replacement
array = [Math.random(), Math.random(), Math.random()];
ready
replacement via function
replace(Math.random(), Math.random(), Math.random());
ready
direct emplacement
array[0] = Math.random();
array[1] = Math.random();
array[2] = Math.random();
ready
emplacement via function
emplace(array, Math.random(), Math.random(), Math.random());
ready

Revisions

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