Author Topic: [OT] - Interesting optimization papers  (Read 3233 times)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
[OT] - Interesting optimization papers
« 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/
Be patient!
This bug will be fixed soon...

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: [OT] - Interesting optimization papers
« Reply #1 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).

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: [OT] - Interesting optimization papers
« Reply #2 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 :)
Be patient!
This bug will be fixed soon...

sethjackson

  • Guest
Re: [OT] - Interesting optimization papers
« Reply #3 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

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: [OT] - Interesting optimization papers
« Reply #4 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: [OT] - Interesting optimization papers
« Reply #5 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.

Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: [OT] - Interesting optimization papers
« Reply #6 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
« Last Edit: July 31, 2006, 09:17:41 pm by Vampyre_Dark »
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~