SaxonMilton

05-02-2013, 01:36 AM

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

Thanks

Saxon

View Full Version : Maximizing the speed of a program

SaxonMilton

05-02-2013, 01:36 AM

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

Thanks

Saxon

thokra

05-02-2013, 02:41 AM

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!

SaxonMilton

05-02-2013, 03:25 AM

Optimizing rendering..

C++..

C++..

thokra

05-02-2013, 03:31 AM

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!

SaxonMilton

05-02-2013, 03:43 AM

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.

thokra

05-02-2013, 03:53 AM

Sure you can. But optimization implies are sub-optimal state. Show us some code you wish to optimize.

SaxonMilton

05-02-2013, 04:28 AM

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.

glBegin( GL_QUADS );

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();

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.

glBegin( GL_QUADS );

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();

thokra

05-02-2013, 04:58 AM

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 (http://www.opengl.org/wiki/Vertex_Specification) 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.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.