Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fast approx. atan2 vs Math.atan2 vs cached atan2 (v8 optimization buster + local scope) 2
(version: 1)
Comparing performance of:
Math.atan2 vs fast approx. atan2 vs cached Math.atan2
Created:
6 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
const ONEQTR_PI = Math.PI / 4; const THRQTR_PI = (3 * Math.PI) / 4; // https://gist.github.com/volkansalma/2972237#file-atan2_approximation-c-L29 const fastAtan2 = (y, x) => { const abs_y = Math.abs(y) + 1e-10; // kludge to prevent 0/0 condition let angle, r; if (x < 0) { r = (x + abs_y) / (abs_y - x); angle = THRQTR_PI; } else { r = (x - abs_y) / (x + abs_y); angle = ONEQTR_PI; } angle += (0.1963 * r * r - 0.9817) * r; return y < 0 ? -angle : angle; }; 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));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Math.atan2
fast approx. atan2
cached Math.atan2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Math.atan2
8668834.0 Ops/sec
fast approx. atan2
12607587.0 Ops/sec
cached Math.atan2
8955988.0 Ops/sec
Related benchmarks:
trigata
trigata
trigata
Fast approx. atan2 vs Math.atan2
Fast approx. atan2 vs Math.atan2 vs cached atan2
Fast approx. atan2 vs Math.atan2 vs cached atan2 (v8 optimization buster)
Fast approx. atan2 vs Math.atan2 vs cached atan2 (v8 optimization buster + local scope)
Fast atan2 vs Math.atan2
Fast approx. atan2 vs Math.atan2 vs fast accurate atan2
Comments
Confirm delete:
Do you really want to delete benchmark?