spread/reduce vs static assign (v2)

Revision 2 of this 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
entries reduce
const result = Object.entries(arr).reduce((acc,[key, val]) => {
	acc[key] = {
		loading: true,
		error: 'error',
		data: val
	}
	return acc;
}, {}) 
ready
entries static
let result = {}
for (const [key, val] of Object.entries(arr)) {
	result[key] = {
		loading: true,
		error: 'error',
		data: val
	}
}
ready

Revisions

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