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 + local scope)
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/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Math.atan2
803787.4 Ops/sec
fast approx. atan2
1237957.2 Ops/sec
cached Math.atan2
1126741.0 Ops/sec
Script Preparation code:
const abs = Math.abs, min = Math.min, max = Math.max, PI = Math.PI, PI2 = PI / 2; var fastAtan2 = (y, x) => { let ax = abs(x); let ay = abs(y); let a = min(ax, ay) / max(x, y); let s = a * a; let r = ((-0.0464964749 * s + 0.15931422) * s - 0.327622764) * s * a + a; if (ay > 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));