Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
conditionally insert properties
https://www.reddit.com/r/javascript/comments/mrzrty/the_shortest_way_to_conditionally_insert/
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Browser:
Chrome 150
Operating system:
Windows
Device Platform:
Desktop
Date tested:
11 days ago
boring
127.3M/s
spread
28.5M/s
Object.assign
19.9M/s
View exact numbers
Test name
Executions per second
✓
boring
127,326,912 Ops/sec
spread
28,516,074 Ops/sec
Object.assign
19,940,932 Ops/sec
Tests:
boring
const obj = { hello: "world" }; if (Math.random()>.5) { obj.foo = "bar"; }
spread
const obj = { hello: "world", ...Math.random()>.5 && { foo: "bar" } };
Object.assign
const obj = Object.assign({ hello: "world" }, Math.random()>.5 && { foo: "bar" });