Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
conditionally insert properties w/ terinary
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 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser:
Firefox 136
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
boring
93060160.0 Ops/sec
spread
18728596.0 Ops/sec
Object.assign
23596478.0 Ops/sec
Terinary
88437080.0 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" });
Terinary
const obj = { hello: "world" }; Math.random()>.5 ? obj.foo = "bar" : false