Array Destructuring Overhead (v2)

Revision 2 of this benchmark created on


Setup

points = [];

for (let i = 0; i < 500; ++i) {
	points.push([Math.random(), Math.random()]);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Explicit
let sum = 0;

for (let i = 0; i < points.length; ++i) {
	const point = points[i];
	sum += point[0] + point[1];
}
ready
Destructuring
let sum = 0;

for (let i = 0; i < points.length; ++i) {
	const [x, y] = points[i];
	sum += x + y;
}
ready
for-of Destructuring
let sum = 0;

for (const [x, y] of points) {
	sum += x + y;
}
ready
Explicit & length cache
let sum = 0;
const length = points.length;

for (let i = 0; i < length; ++i) {
	const point = points[i];
	sum += point[0] + point[1];
}
ready
Explicit & length cache & post-increment
let sum = 0;
const length = points.length;

for (let i = 0; i < length; i++) {
	const point = points[i];
	sum += point[0] + point[1];
}
ready

Revisions

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