Advertisement Jump to content
Sign in to follow this  


This topic is 4914 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

Firstly i wanted to post this in announcments but i said this is dX specific so ill post it here. I have read a article at that says about making a faster vector math. I was curios so i have tried to see how fast is vector add operations (vector + vector). I created console project as shown D3DXVECTOR3 vec1(2.0f,4.0f,6.0f); D3DXVECTOR3 vec2(1.0f,3.0f,5.0f); //here goes various vector implementations D3DXVECTOR3 vec3(2.0f,4.0f,6.0f); Only reason vec3 is there is that when viewing disassembled code in debuger (i use VS is mark what line beggins and i use vec3 only as a marker. I tried following functions and counting how many times i need to press stepinto button 1) vec1 = vec1 + vec2; This is the worst case i needed to press 213 times 2) vec1 += vec2; This nedded only ~87 presses 3) vec1.x = vec1.x + vec2.x vec1.y = vec1.y + vec2.y vec1.z = vec1.z + vec2.z This needed only 12 (twelve) times!!! 4) vec1.x += vec2.x vec1.y += vec2.y vec1.z += vec2.z This needed only 9 (nine) times!!! I think this is a very big offload from procesor if we us this last method. And for better solution review a mentioned article! What do you think?

Share this post

Link to post
Share on other sites
Original post by zlatko_bre_1985
I tried following functions and counting how many times i need to press stepinto button

I don't really understand what you are saying hear. Are you trying to navigate through the call stack? I'm not sure whether you are commenting on the performance of the different vector operation styles or what.

Share this post

Link to post
Share on other sites
Sorry about my bad english :)

Yes i was commenting about performance but i will rephrase it :
I was tring to view what assembly commands compiler generates using various methods for calculating a sum of 2 vectors and putting the result into the 1st.

I was counting number of assembly commands generated by compiler by presing the step into button in debug mode viewing disassembly window.When i press a step into button only one assembly command gets executed and i was counting how many times i need to press step into to reach the end marker(begining of declaration of vec3).

I dont have time to try now with * but ill do it soon and if this is faster way ill post it here.

Dont know if i am wrong but i think next:
Less assembly commands a function (in this case adding 2 vectors) make the faster that function is.

And one question -> Is really method 4 (213/9) times faster then first?

Share this post

Link to post
Share on other sites
1. Checking the disassembly of a debug build is meaningless, because the generated code is not optimized.

2. With the following 2 forms:
vec1 = vec1 + vec2
vec1 += vec2

The difference between the 2 is that the first one creates a temporary vector, the result of the addition, and assigns it back to vec1. However, there's an optimization called Name return value optimization that eliminates the creation of this temporary, in which case the performance of both pieces of code would be the same.

The Visual C++ 7.1 (.NET 2003) supports name return value optimization.

3. You shouldn't worry about the performance of such low-level operations unless you have hard data confirming they're or are going to be a bottleneck. If you don't, just use them.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!