Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Chrome 109
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Math 3610598.8 Ops/sec
Faster 5399397.0 Ops/sec
Fastest 1290306.2 Ops/sec
Script Preparation code:
x
 
let factorialize = function (num) {
    if (num === 0 || num === 1)
        return 1;
    for (let i = num - 1; i >= 1; i--) {
        num *= i;
    }
    return num;
}
let FACT_2 = 1 / factorialize(2);
let FACT_3 = 1 / factorialize(3);
let FACT_4 = 1 / factorialize(4);
let FACT_5 = 1 / factorialize(5);
let FACT_6 = 1 / factorialize(6);
let FACT_7 = 1 / factorialize(7);
const HALF_PI = Math.PI * 0.5;
const DOUBLE_PI = Math.PI * 2;
var mysin = function (angle)
{
    let pow2 = angle * angle;
    let pow4 = pow2 * pow2;
    let pow6 = pow4 * pow2;
    return 1 - pow2 * FACT_2 + pow4 * FACT_4 - pow6 * FACT_6;
}
var mycos = function (angle)
{
    return mysin(angle + HALF_PI);
}
var fastSin = function (x)
{
  if (x < -Math.PI)
        x += DOUBLE_PI;
    else if (x > Math.PI)
            x -= DOUBLE_PI;
    if (x < 0)
        return 1.27323954 * x + 0.405284735 * x * x;
    else
        return 1.27323954 * x - 0.405284735 * x * x;
}
var fastCos = function (x)
{
  return fastSin(x + HALF_PI);
}
Tests:
  • Math

     
    Math.cos(0.4292);
    Math.sin(0.2321);
  • Faster

     
    mycos(0.4292);
    mysin(0.2321);
  • Fastest

     
    fastCos(0.4292);
    fastSin(0.2321);