Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fast approx. atan2 vs Math.atan2
(version: 0)
Comparing performance of:
Math.atan2 vs fast approx. atan2
Created:
4 years ago
by:
Guest
Jump to the latest result
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
Tests:
Math.atan2
var k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e => Math.atan2(e, .5));
fast approx. atan2
var k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e => fastAtan2(e, .5));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.atan2
fast approx. atan2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Math.atan2
10289008.0 Ops/sec
fast approx. atan2
6307680.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. The benchmark is comparing the performance of two implementations of the `atan2` function: the standard `Math.atan2` and a custom, fast approximation implemented by the user (`fastAtan2`). The test cases use arrays to provide input values for the `atan2` function. **Standard Math.atan2** * This implementation uses the built-in JavaScript method `Math.atan2`, which is available in most modern browsers. * The purpose of this comparison is to establish a baseline performance for the standard `atan2` implementation. * Pros: + Widely supported across different browsers and platforms. + Well-optimized by browser vendors. + Easy to implement and use. * Cons: + May not be optimized for specific use cases or edge cases. + Can be slower than a custom implementation, especially for large datasets. **Fast Approximation (fastAtan2)** * This implementation is a hand-rolled approximation of the `atan2` function, designed to be faster than the standard implementation. * The user provides a custom script that defines the `fastAtan2` function, which takes advantage of specific browser optimizations and caching mechanisms. * Pros: + Can achieve significant performance improvements over the standard `Math.atan2` implementation, especially for large datasets or high-performance applications. + Allows developers to fine-tune the implementation for their specific use case. * Cons: + Requires manual effort and expertise to implement correctly. + May not be compatible with all browsers or platforms. **Library: FAT2** The `FAT2` object is a custom data structure used in the fast approximation implementation. It's likely designed to help browser vendors optimize the caching and memoization of frequently accessed values, reducing the overhead of function calls and improving performance. **Special JS feature: None** There are no special JavaScript features or syntax being tested in this benchmark. The implementations use standard JavaScript syntax and don't rely on any experimental or proposal-level features. **Other alternatives** If you want to explore alternative approaches, here are a few options: 1. **V8-specific optimizations**: Browser vendors like Google often optimize specific aspects of the V8 engine for better performance. You could try experimenting with V8-specific optimizations or tricks to improve your custom implementation. 2. **Other benchmarking frameworks**: There are several other benchmarking frameworks available, such as Benchmark.js or jsperf, which offer different features and options for testing performance. 3. **Custom microbenchmarking libraries**: Some developers create custom microbenchmarking libraries tailored to specific use cases or platforms. These libraries often provide additional features and optimizations not available in standard JavaScript implementations. Keep in mind that each approach has its pros and cons, and the best choice depends on your specific requirements and goals.
Related benchmarks:
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
Comments
Confirm delete:
Do you really want to delete benchmark?