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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
custom (branched)
9.0M/s
custom (branchless)
8.8M/s
native
8.6M/s
-1 ** a
8.5M/s
View exact numbers
Test name
Executions per second
✓
custom (branched)
9,023,908 Ops/sec
custom (branchless)
8,792,451 Ops/sec
native
8,572,205 Ops/sec
-1 ** a
8,547,974 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);