Destructure

Benchmark created on


Description

See the overhead of putting something into an array and then destructuring it.

Setup

const array = [0, 1, 2, 3, 4, 10, 11, 12, 13, 14];
let   index = 0;

function Next()
{
	const prev = array[index];
	++index;
	return prev;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Normal
const a = Next();
const b = Next();
const c = Next();
const d = Next();
const x = d + (c << 8) + (b << 16) + (a << 24);
ready
Destructure
const [a, b, c, d] = [Next(), Next(), Next(), Next()];
const x = d + (c << 8) + (b << 16) + (a << 24);
ready
1 liner
const x = (Next() << 24) + (Next() << 16) + (Next() << 8) + Next();
ready
1 liner OR
const x = (Next() << 24) | (Next() << 16) | (Next() << 8) | Next();
ready
Normal OR
const a = Next();
const b = Next();
const c = Next();
const d = Next();
const x = d | (c << 8) | (b << 16) | (a << 24);
ready
Destructure OR
const [a, b, c, d] = [Next(), Next(), Next(), Next()];
const x = d | (c << 8) | (b << 16) | (a << 24);
ready
Destructure OR2
const [a, b, c, d] = [Next(), Next(), Next(), Next()];
const x = (a << 24) | (b << 16) | (c << 8) | d;
ready

Revisions

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