# D3DXVECTOR3 Math LOOK

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

## 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 flipcode.com http://www.flipcode.com/articles/article_fastervectormath.shtml 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 2003.net)there 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 on other sites
Quote:
 Original post by zlatko_bre_1985I 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 on other sites

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 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
and
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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633289
• Total Posts
3011231
• ### Who's Online (See full list)

There are no registered users currently online

×