Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
fast absolute value (branched & branchless) vs abs vs ** -1
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/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
native
5635359.5 Ops/sec
custom (branchless)
5644617.0 Ops/sec
custom (branched)
5658351.5 Ops/sec
-1 ** a
5559887.0 Ops/sec
Script Preparation code:
var abs = Math.abs; var fastAV = a => a - ((a < 0) * a * 2); var fastAV2 = a => a < 0 ? -a : a; var fastAV3 = a => (-1) ** (a > 0) * a;
Tests:
native
abs(-10); abs(10); abs(-10.1); abs(10.1);
custom (branchless)
fastAV(-10); fastAV(10); fastAV(-10.1); fastAV(10.1);
custom (branched)
fastAV2(-10); fastAV2(10); fastAV2(-10.1); fastAV2(10.1);
-1 ** a
fastAV3(-10); fastAV3(10); fastAV3(-10.1); fastAV3(10.1);