I agree with xismn that you
really don't need to concern yourself with these matters just yet, so this is just FYI:
For the purposes of optimization, taking a simple operation, putting it in a long loop, and timing the loop is useless. It doesn't tell you how expensive is, just how fast the computer is at performing that operation. It's useless for two reasons:
1. Compilers are often very clever, and can do rather unexpected things to your code. That one line you're so worried about might not even exist in the generated executable.
2. Modern CPUs are complex beasts. Because of pipelining and caching, the performance of two copies of the same sequence of instructions may be different depending on what was previously executed. So, in this example:
1 2 3 4 5 6 7 8 9 10
|
void a(){
for (/*...*/){
g();
}
}
void b(){
f();
g();
}
|
timing a() may noy tell you anything about how long b() will take.
When optimizing, one normally uses a profiler. A profiler is a tool that's capable of measuring the performance of a program at various levels of precision (function, statement, instruction, etc.) without modifying the source code.
Now, timing isn't completely useless, either. If you want to optimize a complex operation (e.g. compressing a file), timing the operation as a whole is useful to know if your changes are overall improvements or not.