Performance difference between XMVector3Length and XMVector3LengthSq

Started by
2 comments, last by 215648 10 years ago

which should be faster? Is XMVector3LengthSq faster compared to XMVector3Length? (because I think XMVector3Length involves a square root while XMVector3LengthSq just gives out distance without computing Square root)

Advertisement

XMVector3Length returns the length of the vector.

XMVector3LengthSq returns the squared length of the vector.

If the length of the vector is e.g. 13, then the squared length is 13 * 13 = 169.

XMVector3Length is just square root of XMVector3LengthSq.

Thus:

XMVector3Length gives actual length, but isn't as fast.

XMVector3LengthSq is faster, but doesn't give actual length. It can still be used for various calculations.

As an example, these should give the same result:

1) if (XMVector3Length(myVector) < 5)

2) if (XMVector3LengthSq(myVector) < 25)

Hello to all my stalkers.

Just like Lactose! said, in general, use squared lengths whenever possible. Which tends to be just for comparing...

“We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil” - Donald E. Knuth, Structured Programming with go to Statements

"First you learn the value of abstraction, then you learn the cost of abstraction, then you're ready to engineer" - Ken Beck, Twitter

Okay, thanks. I'm already using square lengths but I just wanted to confirm that.

This topic is closed to new replies.

Advertisement