For$
<!-- begin site header -->
<div id=

Author Topic: Small optimizations  (Read 7907 times)

Josko88

  • Newbie
  • *
  • Posts: 1
    • View Profile
Small optimizations
« on: November 27, 2010, 09:13:27 pm »
Hello,

can I suggest using (const) references passing where available (ie. std::strings) and using prefix instead of postfix operators (seems like you're using both so at least decide which one ;)). Not the biggest jumps in performance but they won't slow things down for sure.

nicklozon

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Small optimizations
« Reply #1 on: November 29, 2010, 04:01:43 am »
Should ALWAYS use prefix over postfix unless you would be copying the object anyway.

Always avoid using the copy constructor for less overhead!

ReDucTor

  • Developer
  • Newbie
  • ****
  • Posts: 10
    • View Profile
Re: Small optimizations
« Reply #2 on: November 29, 2010, 08:34:41 am »
Yes, these are both good programming, even though they are the first things to be optimized with most compilers, the const reference is more important then incrementing being post or pre, unless its an object which is being copied because its had the increment operators overloaded..

nicklozon

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Small optimizations
« Reply #3 on: November 30, 2010, 02:36:26 am »
Ya, good compilers won't return a temporary value with post-increment if no operation is being performed on it. And if an operation is done on it, it was most likely intended to be performed on a post-increment.

So ya, the only time you may gain a performance gain on post vs pre increment is on an object where the operator is overloaded - good call.