Jump to content
• ### What is your GameDev Story?

• Advertisement

# 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

##### 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

##### 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

##### Share on other sites

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

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 11
• 9
• 9
• 41
• Advertisement
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015707
×

## 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!