Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
Chrome 101
Windows
Desktop
2 years ago
Test name Executions per second
sin 5.6 Ops/sec
cos 5.6 Ops/sec
tan 5.6 Ops/sec
asin 4.8 Ops/sec
acos 5.5 Ops/sec
atan 5.2 Ops/sec
atan2 3.0 Ops/sec
Script Preparation code:
x
 
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]); }