Array initialization

Benchmark created on


Setup

const MAX_LENGTH = 100000;

const RANDOM_INSERTS = 10000;
const random = () => Math.floor(Math.random() * MAX_LENGTH);

Test runner

Ready to run.

Testing in
TestOps/sec
Prelength Random Insert
const a = new Array(MAX_LENGTH);


for (let i = 0; i < RANDOM_INSERTS; i++) {
	const index = random()
	a[index] = "TEST";

}
ready
Regular Random Insert
const a = [];


for (let i = 0; i < RANDOM_INSERTS; i++) {
	const index = random()
	a[index] = "TEST";

}
ready
Prelength Linear Insert
const a = new Array(MAX_LENGTH);


for (let i = 0; i < MAX_LENGTH; i++) {
	a[i] = "TEST";
}
ready
Regular Linear Insert
const a = [];


for (let i = 0; i < MAX_LENGTH; i++) {
	a[i] = "TEST";
}
ready

Revisions

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