spread/reduce vs static assign

Benchmark created on


Setup

const arr = Array.from({length: 25}).map((_, i) => (i % 25) + 66 ).reduce((memo, n, i, a) => i === a.length-1 ? memo : ({...memo, [String.fromCharCode(n)]:String.fromCharCode(a[i+1])}), {});
const keys = Object.keys(arr);

Test runner

Ready to run.

Testing in
TestOps/sec
spread/reduce
const result = keys.reduce((acc, key) => {
	return {
		...acc,
		[key]: {
			loading: true, 
			error: 'error',
			data: arr[key]
		}
	};
}, {});
ready
static assign
let result = {};
for (const key of keys) {
	result[key] = {
		loading: true,
		error: 'error',
		data: arr[key]
	}
}
ready

Revisions

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