array destructure fast

Benchmark created on


Setup

const arr = [...Array(1000).keys()];
const destructure = (arr, ...names) => {
	let result = {};
	for(let i = 0; i < names.length; i++) {
		result[names[i]] = arr[i];
	}
	return result;
}

Test runner

Ready to run.

Testing in
TestOps/sec
manual
const a = arr[0];
const b = arr[1];
const c = arr[2];
ready
helper
const {a, b, c} = destructure(arr, "a", "b", "c");
ready

Revisions

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