Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
fast approx. atan2
2.3M/s
cached Math.atan2
1.9M/s
Math.atan2
1.5M/s
View exact numbers
Test name
Executions per second
✓
fast approx. atan2
2,290,957 Ops/sec
cached Math.atan2
1,920,872 Ops/sec
Math.atan2
1,455,808 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));