Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General C++ Performance Improvement Tips [closed]

Tags:

c++

Could someone point me to an article, or write some tips right here about some C++ programming habits that are generally valid (no real drawbacks) and improves performance? I do not mean programming patterns and algorithm complexity - I need small things like how you define your functions, things to do/to avoid in loops, what to allocate on the stack, what on the heap, and so on.

It's not about making a particular software faster, also it's not about how to create a clean software design, but rather programming habits that - if you always apply them, you will make your code rather a little bit faster than a little bit slower.

like image 518
genesys Avatar asked Jan 08 '10 19:01

genesys


1 Answers

A number of the tips in Effective C++, More Effective C++, Effective STL and C++ Coding Standards are along this line.

A simple example of such a tip: use preincrement (++i) rather than postincrement (i++) when possible. This is especially important with iterators, as postincrement involves copying the iterator. You optimizer may be able to undo this, but it isn't any extra work to write preincrement instead, so why take the risk?

like image 70
Laurence Gonsalves Avatar answered Oct 03 '22 22:10

Laurence Gonsalves