News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

[OT] - Interesting optimization papers

Started by mandrav, July 31, 2006, 09:09:13 AM

Previous topic - Next topic

mandrav

Here's a site I stumbled upon the other day with a few interesting papers regarding C++ code optimization.

http://www.agner.org/optimize/
Be patient!
This bug will be fixed soon...

Game_Ender

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).

mandrav

Quote from: Game_Ender on July 31, 2006, 02:30:35 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 :)
Be patient!
This bug will be fixed soon...

sethjackson

Quote from: mandrav on July 31, 2006, 02:40:41 PM
Quote from: Game_Ender on July 31, 2006, 02:30:35 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

thomas

Quote from: Game_Ender on July 31, 2006, 02:30:35 PMOne 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Game_Ender

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.

Vampyre_Dark

#6
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
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~