mercredi 1 juillet 2015

Same operations taking different time

I am in the process of optimizing my code for my n-body simulator, and when profiling my code, have seen this:

enter image description here

These two lines,


float diffX = (pNode->CenterOfMassx - pBody->posX);
float diffY = (pNode->CenterOfMassy - pBody->posY);

Where pNode is a pointer to a object of type Node that I have defined, and contains (with other things) 2 floats, CenterOfMassx and CenterOfMassy

Where pBody is a pointer to a object of type Body that I have defined, and contains (with other things) 2 floats, posX and posY.


Should take the same amount of time, but do not. In fact the first line accounts for 0.46% of function samples, but the second accounts for 5.20%.

Now I can see the second line has 3 instructions, and the first only has one.

My question is why do these seemingly do the same thing but in practice to different things?

Aucun commentaire:

Enregistrer un commentaire