What smac89 forgot to mention is that the function you're timing spends nearly all of its time in its loop. Inlining makes sense when a function is called many times. For example, if you were to move the loop to the outside of the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//Before:
//Function:
for (i = 0; i < 9999; i++){
//...
}
//Call:
function();
//After:
//Function:
//...
//Call:
for (i = 0; i < 9999; i++){
function();
}
|
(Assume that things have been moved around appropriately for the above to make sense.)
Also, clock() measures intervals of 1/CLOCKS_PER_SEC seconds, not CPU clocks. On Windows, CLOCKS_PER_SEC == 1000. Regardless of that, the function has a limited resolution. If timed values oscillate between, say, 100 and 115, it means one of two things, or a combination of both:
1. The true time is somewhere between those two. The precision limit doesn't allow more accurate timing.
2. Other processes are using CPU time, throwing the measurement off.
#1 can be mitigated by timing longer operations, if function() takes 100 ms plus or minus 15 ms (that's the approximate accuracy of the Windows clock), time 100 runs of the function. You'll never get an oscillation greater than the clock precision, so instead of an error of 15%, you'll get an error of 0.15%.