Jump to content
  • Advertisement
Sign in to follow this  
Drythe

Slowdown!

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

I'm having some trouble with slowdown and tried to pinpoint what's going wrong by testing it with the following code. Here are 2 different versions of a loop statement that do the same thing. With the first one, I'm getting about 130,000 program cycles/sec and the second one, 18:P As you can see, the only difference is in one I'm writing the math out manually, and the second I'm using a function that does the same thing. Good: POINT3D LightPos = POINT3D(34, 546, 56); float u; for (int i = 0; i < 13976; i++) { for (int k = 0; k < 3; k++) { //this is pasted 16 times in the real code u = pow((LightPos.x * LightPos.x) + (LightPos.y * LightPos.y) +(LightPos.z * LightPos.z), 0.5); } } Bad: POINT3D LightPos = POINT3D(34, 546, 56); float u; for (int i = 0; i < 13976; i++) { for (int k = 0; k < 3; k++) { //this is pasted 16 times in the real code u = GetLength( LightPos); } } Here are the definitions used: //////////////////////////////////////////////////////////////////////////// inline const float GetLength(const POINT3D& Vector) { return pow((Vector.x * Vector.x) + (Vector.y * Vector.y) + (Vector.z * Vector.z), 0.5); } //////////////////////////////////////////////////////////////////////////// typedef struct POINT3D { public: POINT3D() {}; POINT3D(float xf, float yf, float zf) {x = xf; y = yf; z = zf;} float x, y, z; }POINT3D; *A couple notes: the inline seems to be working I guess.. because when I remove it, the 18 program cycles/sec goes down to 9. Also, when I move the 'float u;' into the header file, the 18 goes to 32. I don't know if this is a hint of any kind. Also, this data isn't being used anywhere in the program. in fact, this is about all the program is, since I commented all of the main stuff out. Everything's still being compiled though... P.S. sorry about the formatting... how do you do those little code boxes on this forum?

Share this post


Link to post
Share on other sites
Advertisement
well, I do use the double fors in the final code, but I commented just about everything out to test the slowdown problem.

Share this post


Link to post
Share on other sites
GetLength( LightPos);
Does it has the exact same code as that line where you do the calculations?

Share this post


Link to post
Share on other sites
yes

////////////////////////////////////////////////////////////////////////////
inline const float GetLength(const POINT3D& Vector)
{

return pow((Vector.x * Vector.x) +
(Vector.y * Vector.y) +
(Vector.z * Vector.z), 0.5);

}

Share this post


Link to post
Share on other sites
I mean.. it does the same thing, but there must be a key difference on the compiler level or something. Possibly something to do with memory? i dunno:)

Share this post


Link to post
Share on other sites
Can you take a look at the assembly code the compiler generates in both cases?
You can post it here.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!