# Maximizing the speed of a program

• 05-02-2013, 01:36 AM
SaxonMilton
Maximizing the speed of a program
Ok, so guys, could you please give me some general tips on code structure that can help maximize the speed of my program
Thanks
Saxon
• 05-02-2013, 02:41 AM
thokra
Ehm, plenty. What's the scenario? Are we talking general optimization or optimizing rendering? Are we talking C/C++ or other languages? Please be more specific when asking quetsitons!
• 05-02-2013, 03:25 AM
SaxonMilton
Optimizing rendering..
C++..
• 05-02-2013, 03:31 AM
thokra
An specific problems? You can't optimize unless you know where your bottelnecks are. Premature optimization is the root of all evil and high cholesterol!
• 05-02-2013, 03:43 AM
SaxonMilton
No, I have just been playing around with code structure, and I was curious as to whether or not there are actually things that can be done in order to optimize the speed.
• 05-02-2013, 03:53 AM
thokra
Sure you can. But optimization implies are sub-optimal state. Show us some code you wish to optimize.
• 05-02-2013, 04:28 AM
SaxonMilton
ok, specifically
in the case of drawing a cube, what is faster, the following code,,
or a loop coupled with an algorithm that can change the the x, y and z variables to the corresponding values.

glVertex3f( x, y, z);
glVertex3f(-x, y, z);
glVertex3f(-x,-y, z);
glVertex3f( x,-y, z);

glVertex3f( x, y,-z);
glVertex3f(-x, y,-z);
glVertex3f(-x, y, z);
glVertex3f( x, y, z);

glVertex3f(-x, y,-z);
glVertex3f( x, y,-z);
glVertex3f( x,-y,-z);
glVertex3f(-x,-y,-z);

glVertex3f( x, y,-z);
glVertex3f( x, y, z);
glVertex3f( x,-y, z);
glVertex3f( x,-y,-z);

glVertex3f(-x, y, z);
glVertex3f(-x, y,-z);
glVertex3f(-x,-y,-z);
glVertex3f(-x,-y, z);

glVertex3f( x,-y, z);
glVertex3f(-x,-y, z);
glVertex3f(-x,-y,-z);
glVertex3f( x,-y,-z);
glEnd();
• 05-02-2013, 04:58 AM
thokra
If the compiler unrolls the loop, there isn't a difference at all and in this case it very well might do that. You should check out how to render stuff nowadays. The code you posted is so 1992. It's not that tragic for a cube, but for mesh with a few hundrd or thousand vertices, your current method (called immediate mode) is the slowest possible.