Array destructuring vs mutable op + Date.now()

Benchmark created on


Setup

function immutable(obj, key, value) {
	return {...obj, [key]: value}
}

function mutable(obj, key, value) {
	obj[key] = value;
	return Date.now();
}

function mutableCreateObject(obj, key, value) {
	obj[key] = value;
	return {};
}

Test runner

Ready to run.

Testing in
TestOps/sec
Immutable
const a = {b: 1, c: "lala", d: 88};
let hh = immutable(a, "b", Math.floor(Math.random() * 100))
hh = immutable(a, "c", "Shoho")

ready
Mutable
const a = {b: 1, c: "lala", d: 88};
let hh = mutable(a, "b", Math.floor(Math.random() * 100))
hh = mutable(a, "c", "Shoho")
ready
Mutable Object
const a = {b: 1, c: "lala", d: 88};
let hh = mutable(a, "b", Math.floor(Math.random() * 100))
hh = mutableCreateObject(a, "c", "Shoho")
ready

Revisions

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