Point comparison - which method is fastest?

Just out of curiosity, there are several methods that one can use to compare two points, notably:

if ptA.DistanceTo(ptB)<tol: return True

if ptA.DistanceToSquared(ptB)<tol: return True (supposedly faster than above)

if ptA.EpsilonEquals(ptB,tol): return True

if ptA.CompareTo(ptB)==0: return True (no tolerance value?)

and more…

Which is the fastest to run?

DistanceTo will use a sqare root, which is expensive to calculate, hence DistanceToSquared exists which does not do that. You do have to square the tolerance to achieve the same effect though.

EpsilonEquals compares the X,Y,Z elements within tolerance, no square root, but it has some overhead to check for infinity, NaN and small values. Lastly, CompareTo just compares the X,Y,Z elements and returns true if they are exactly the same, which is why there’s no tolerance.

The fastest? That is of course not exactly clear except for the difference between DistanceTo and DistanceToSquare. The others should be comparable. Of course these comparison all involve a method call, which has a bit of overhead, so cooking up a comparison without a method call may be faster. To get more insight in which is faster, use profiling - i.e. check the different methods for the same input on a large number of compares (>10 million) and see which is faster.

Ahh, thanks for that info.