array.from vs push

Benchmark created on


Preparation HTML

	

Setup

const array = new Array(100);
function* gen(array) {
	for (let i = 0; i < array.length; i++){
		yield array[i];
	}
}
function push(iterable){
	const iterator = iterable[Symbol.iterator]();
	const ret = [];
	let state;
	while ((state = iterator.next()) && !state.done){
		ret.push(state.value);
	}
	return ret;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from
Array.from(gen(array));
ready
push
push(array)
ready

Revisions

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