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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0
Browser:
Chrome 148
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Benchmark engine:
Benchmark.js
Terinary
104.6M/s
boring
103.7M/s
spread
42.7M/s
Object.assign
33.7M/s
View exact numbers
Test name
Executions per second
✓
Terinary
104,587,800 Ops/sec
boring
103,672,168 Ops/sec
spread
42,743,488 Ops/sec
Object.assign
33,700,044 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