Sine approximation

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [ Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI,
            Math.random() * 2 * Math.PI ];
  
  function sine(x) {
    var B = 4 / Math.PI,
        C = -4 / (Math.PI * Math.PI),
        y = B * x + C * x * Math.abs(x);
  
    return y;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
built-in pi
for (var i = 0; i < a.length; i++) {
  Math.sin(a[i]);
}
pending…
My sine
for (var i = 0; i < a.length; i++) {
  sine(a[i]);
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments