Fork me on GitHub
  November 20, 2018, 09:42:15 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Small optimizations  (Read 2539 times)
Josko88
Newbie
*
Posts: 1


View Profile
« 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 Wink). Not the biggest jumps in performance but they won't slow things down for sure.
Logged
nicklozon
Newbie
*
Posts: 5


View Profile
« 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!
Logged
ReDucTor
Developer
Newbie
****
Posts: 10


View Profile
« 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..
Logged
nicklozon
Newbie
*
Posts: 5


View Profile
« 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!