Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Branchless vs Branched Angle Inversion
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/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
branched
7105855.5 Ops/sec
branchless
7216884.5 Ops/sec
branchless in-scope caching
7257170.5 Ops/sec
branchless out of scope caching
6805007.5 Ops/sec
Script Preparation code:
const PI = Math.PI; function invertAngleBranch(angle) { if (angle + PI > PI) return (angle - PI) else return angle + PI }; function invertAngleBranchless(angle) { return (angle + PI > PI) * (angle - PI) + (angle + PI <= PI) * (angle + PI); }; function invertAngleBranchlessC1(angle) { let tmp = angle + PI; return (tmp > PI) * (angle - PI) + (tmp <= PI) * tmp; }; let tmp2 = NaN; //initialize with float for v8 function invertAngleBranchlessC2(angle) { tmp2 = angle + PI; return (tmp2 > PI) * (angle - PI) + (tmp2 <= PI) * tmp2; }; var rnd = Math.random;
Tests:
branched
return invertAngleBranch(rnd());
branchless
return invertAngleBranchless(rnd());
branchless in-scope caching
return invertAngleBranchlessC1(rnd());
branchless out of scope caching
return invertAngleBranchlessC2(rnd());