Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: mandrav on July 31, 2006, 09:09:13 am

Title: [OT] - Interesting optimization papers
Post by: mandrav on July 31, 2006, 09:09:13 am
Here's a site I stumbled upon the other day with a few interesting papers regarding C++ code optimization.

http://www.agner.org/optimize/
Title: Re: [OT] - Interesting optimization papers
Post by: Game_Ender on July 31, 2006, 02:30:35 pm
That is very good site.  One of the parts I don't like is where basically says to use C++ like its C with classes, ie: No run time type information or exception handling.

Good to see you back mandrav, I hope whatever caused your absence went very well (never did learn why you were away).
Title: Re: [OT] - Interesting optimization papers
Post by: mandrav on July 31, 2006, 02:40:41 pm
Good to see you back mandrav, I hope whatever caused your absence went very well (never did learn why you were away).

Hum, I was on vacations  :oops: . Thanks anyway :)
Title: Re: [OT] - Interesting optimization papers
Post by: sethjackson on July 31, 2006, 03:25:12 pm
Good to see you back mandrav, I hope whatever caused your absence went very well (never did learn why you were away).

Hum, I was on vacations  :oops: . Thanks anyway :)

Now everyone has to get back to work. :lol:

Nice to see you back. :D
Title: Re: [OT] - Interesting optimization papers
Post by: thomas on July 31, 2006, 03:43:23 pm
One of the parts I don't like is where basically says to use C++ like its C with classes, ie: No run time type information or exception handling.
From the strict viewpoint of optimisation, he is right, though. It is no secret that both of these consume considerable CPU time. I am not denying the useful applications and advantages of exceptions, but they are not free.

I don't have figures at hand for RTTI, but I have timed the overhead caused by enabling exceptions with gcc 3.4 some months ago. Simply turning on exceptions (without actually throwing anything) makes your code about 6-8% slower.
The time for throwing and catching an exception (which luckily does not happen in "normal" operation) is unpredictable, it could take milliseconds in the worst case. In the "normal" case, you can assume it is something on the order of 100 to 1000 times more expensive than a conditional branch (depends on how much stack has to be unwound and on what happens in destructors).

Thus, from the strict viewpoint of optimisation, it is not entirely unreasonable discourage exceptions where they are not absolutely necessary.
Title: Re: [OT] - Interesting optimization papers
Post by: Game_Ender on July 31, 2006, 06:47:47 pm
I agree, I just think those are two very useful features of the language.  And its worth even a 10% performance loss for the better code it produces, from the standpoint of read ability and maintainability.  Properly designed exception handling code can be cleaner and easy to understand.
Title: Re: [OT] - Interesting optimization papers
Post by: Vampyre_Dark on July 31, 2006, 09:14:18 pm
The author is right, users don't like long load times...
Here is a demo: http://www.youtube.com/watch?v=kBVmfIUR1DA  :lol:

-edit-

And here he is optimized

http://www.youtube.com/watch?v=nTDxahJj2Qw