Sine approximation

JavaScript performance comparison

Test case created

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 unknown unknown
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

Add a comment