Advertisement Jump to content
Sign in to follow this  
newtechnology

Performance difference between XMVector3Length and XMVector3LengthSq

This topic is 1759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!