dict-copy (v2)

Revision 2 of this benchmark created on


Setup

var x = {};

for (let i = 0; i < 1_000_000; i++) {
	const channel = `channel:number_${i}`;
	const channelDesc = { channel, type: 'int' };
	x[channel] = channelDesc;
}

Test runner

Ready to run.

Testing in
TestOps/sec
single immutable update
const newChannel = 'sams_new_channels:number_1';
const y = {
	...x,
	[newChannel]: { channel: newChannel, type: ' int' }
}
ready
object.assign
const newChannels = {};
for (let i = 0; i < 10; i++) {
    const newChannel = `sams_new_channels:number_${i}`;
    newChannels[newChannel] = { channel: newChannel, type: 'int' };
}

z = Object.assign({}, x, newChannels);
ready
10 immutable updates
let updated = x;

for (let i = 0; i < 10; i++) {
    const newChannel = `sams_new_channels:number_${i}`;
    updated = {
		...updated,
		[newChannel]: { channel: newChannel, type: 'int' }
	};
}
ready
Mutation
const newChannel = 'sams_new_channels:number_11';

x[newChannel] = { channel: newChannel, type: ' int' };
ready

Revisions

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