Spread vs Array.from vs push

Benchmark created on


Setup

const _size = 1_000;
const _values = new Array(_size);

for (let i = 0; i < _size; i++) {
	_values[i] = Math.random();
}

function* getValues() {
	for (let i = 0; i < _size; i++) {
		yield _values[i];
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
const vals = [...getValues()];
ready
Array.from
const vals = Array.from(getValues());
ready
For/of with push
const vals = [];
for (const v of getValues()) vals.push(v);
ready

Revisions

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