Uint array push vs assign

Benchmark created on


Setup

function push(length) {
	const array = [];
    for (var i = 0; i < length; i++) {
    	array.push(0);
    }
    return new Uint8Array(array);
}

function assign(length) {
	const array = new Uint8Array(length);
    for (var i = 0; i < length; i++) {
    	array[i] = 0;
    }
    return array;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Push
const array = push(10000);
ready
Assign
const array = assign(10000);
ready

Revisions

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