Mineserver Community

Mineserver => Discussion => Topic started by: Josko88 on November 27, 2010, 09:13:27 pm



Title: Small optimizations
Post by: Josko88 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.


Title: Re: Small optimizations
Post by: nicklozon 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!


Title: Re: Small optimizations
Post by: ReDucTor 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..


Title: Re: Small optimizations
Post by: nicklozon 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.