sin, cos vs sqrt (v2)

Revision 2 of this benchmark created on


Description

want to know if it's faster to get a unit vector with sqrt or with trig functions

Preparation HTML

<script>
  var dx = 70,
      dy = 90;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
sqrt
var r = Math.sqrt(dx * dx + dy * dy),
    ux = 10 * dx / r,
    uy = 10 * dy / r;
ready
trig
var a = 2.24,
    ux = 10 * Math.cos(a),
    uy = 10 * Math.sin(a);
ready

Revisions

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