Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Ternary operator VS Multi-assign VS Function call
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Chrome OS 14541.0.0
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Ternary
39773904.0 Ops/sec
Assign
38801140.0 Ops/sec
Function
39871176.0 Ops/sec
Simple
23352764.0 Ops/sec
Script Preparation code:
const n = Math.random() * 1000;
Tests:
Ternary
const t1 = n < 750 ? n < 500 ? n < 250 ? 0 : 1 : 2 : 3;
Assign
if ( n < 250 ) { const t2 = 0 } else if ( n < 500 ) { const t2 = 1 } else if ( n < 750 ) { const t2 = 2 } else { const t2 = 3 }
Function
const t3 = (n=>{ if ( n < 250 ) return 0; if ( n < 500 ) return 1; if ( n < 750 ) return 2; return 3; })(n);
Simple
const t4 = parseInt( n % 250 );