Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
if vs ternary vs multiplication
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
if
4.9M/s
ternary
4.8M/s
multiply const
4.5M/s
multiply
2.5M/s
View exact numbers
Test name
Executions per second
✓
if
4,880,684 Ops/sec
ternary
4,838,282 Ops/sec
multiply const
4,467,896 Ops/sec
multiply
2,511,325 Ops/sec
Script Preparation code:
this.n = Math.floor(Math.random() * 10000);
Tests:
if
if(this.n%2) { return 3*this.n+1; } else { return this.n/2; }
ternary
return (this.n%2)?3*this.n+1:this.n/2;
multiply
return (this.n%2)*(3*this.n+1)+(!(this.n%2))*this.n/2;
multiply const
const n2=this.n%2; return n2*(3*this.n+1)+!n2*this.n/2;