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)
Performance difference between XMVector3Length and XMVector3LengthSq
GDNet+ - Reputation: 8599
Posted 29 March 2014 - 05:14 AM
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.
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.
Members - Reputation: 375
Posted 29 March 2014 - 08:06 AM
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