You should use a profiler to find the bottlenecks when you've finished your program. It's the fastest and easiest way.
Don't forget most reliable.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
A profiler is a system that tracks the execution of your program to find out where it spends its time.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
A profiler is a piece of software that measures the amount of time, number of calls or similar that a particular piece of code is used.
There are two forms of profilers:
1. Sampling profiler - oprofile, vtune for example.
This method installs some extra code in certain interrupt(s) to capture where the code is executing when the interrupt is taken [and in modern processors also take advantage of "performance counters"], and can non-intrusively show pieces of code that are "heavy" on the CPU.
2. Intrusive profiler - gprof for example.
This method adds extra code to indicate which parts of the code is performed how many times. Obviously this is only necessary on basic blocks [that is, any code that has a jump to or from it, so loops and conditional code], so not every line of source code need instrumenting. But the additional code does change the behaviour of the code itself, and in small functions, it may double or triple the execution time - but you do get a very exact number of calls to the function, etc.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Also, under C++, the intrusive profilers typically need compiler support, while the sampling profilers don't. To use gprof, you need to compile and link your program with the -pg GCC option.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
sounds cool, i'll give them a try.
Ubuntu Desktop
GCC/G++
Geany (for quick projects)
Anjuta (for larger things)