tan atan2 vs pythag

Benchmark created by arraydifferences on


Description

tan(radian) = o/a Math.min(x2-x1,y2-y1))/sin((Math.atan2(y2-y1,x2-x1))%(Math.PI/2))

VS

Math.sqrt((x2-x1)(x2-x1)+(y2-y1)(y2-y1));

Setup

var x1 = Math.random() * 1000;
    var y1 = Math.random() * 1000;
    var x2 = Math.random() * 1000;
    var y2 = Math.random() * 1000;
    var dx = x2 - x1;
    var dy = y2 - y1;
    var halfpi = (Math.PI / 2);

Test runner

Ready to run.

Testing in
TestOps/sec
trig
console.log(Math.min(dx, dy) / Math.sin((Math.atan2(dy, dx)) % halfpi));
ready
pt
console.log(Math.sqrt(dx * dx + dy * dy));
ready

Revisions

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

  • Revision 1: published by arraydifferences on