Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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 (Macintosh; Intel Mac OS X 10.15; rv:151.0) Gecko/20100101 Firefox/151.0
Browser:
Firefox 151
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 months ago
Benchmark engine:
Benchmark.js
boring
110.9M/s
Terinary
108.6M/s
Object.assign
36.0M/s
spread
30.2M/s
View exact numbers
Test name
Executions per second
✓
boring
110,892,784 Ops/sec
Terinary
108,601,560 Ops/sec
Object.assign
36,023,648 Ops/sec
spread
30,178,944 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