Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Fast approx. atan2 vs Math.atan2 vs cached atan2 (v8 optimization buster)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0
Browser:
Firefox 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Math.atan2
1633291.6 Ops/sec
fast approx. atan2
1549026.4 Ops/sec
cached Math.atan2
1509974.4 Ops/sec
Script Preparation code:
const abs = Math.abs, min = Math.min, max = Math.max, PI = Math.PI, PI2 = PI / 2; const FAT2 = { ax: 0.1, ay: 0.1 }; //variables for gc (v8 optimizations); let a = 0.1, s = 0.1, r = 0.1; var fastAtan2 = (y, x) => { FAT2.ax = abs(x); FAT2.ay = abs(y); a = min(FAT2.ax, FAT2.ay) / max(x, y); s = a * a; r = ((-0.0464964749 * s + 0.15931422) * s - 0.327622764) * s * a + a; if (FAT2.ay > FAT2.ax) r = PI2 - r; if (x < 0) r = PI - r; if (y < 0) r = -r; return r; }; //this is the fastest i can get it rn var atan2 = Math.atan2;
Tests:
Math.atan2
eval(''); var k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e => Math.atan2(e, .5));
fast approx. atan2
eval(''); var k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e => fastAtan2(e, .5));
cached Math.atan2
eval(''); var k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e => atan2(e, .5));