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
Test name
Executions per second
if
4880684.0 Ops/sec
ternary
4838282.5 Ops/sec
multiply
2511325.0 Ops/sec
multiply const
4467896.5 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;