Jump to content

  • Log In with Google      Sign In   
  • Create Account


Performance difference between XMVector3Length and XMVector3LengthSq


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 newtechnology   Members   -  Reputation: 584

Like
0Likes
Like

Posted 29 March 2014 - 01:38 AM

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)



Sponsor:

#2 Lactose!   GDNet+   -  Reputation: 2520

Like
3Likes
Like

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.

 

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)



#3 Javier Meseguer de Paz   Members   -  Reputation: 337

Like
0Likes
Like

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


#4 newtechnology   Members   -  Reputation: 584

Like
0Likes
Like

Posted 30 March 2014 - 01:56 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS