Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
testing ternary vs &&
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Browser:
Safari 17
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
spread ternary
910627.1 Ops/sec
spread &&
1195137.4 Ops/sec
Script Preparation code:
function translateBySpread (a) { const b = { ...(a.id && { id: a.id }), ...(a.foo && { foo: a.foo}) } return b; } function translateByTernary (a) { const b = { ...(a.id ? { id: a.id } : {}), ...(a.foo ? { foo: a.foo} : {}) } return b; }
Tests:
spread ternary
translateByTernary({ id: '12345', type: 'article' });
spread &&
translateBySpread({ id: '12345', type: 'article' });