Nothing really, its just in Code::block you get the execution time automatically with out having to calculate it |
You cannot reliably benchmark code that way, as it is timing everything including process startup and shutdown... both of which are likely taking 100x longer than your simple factorial code.
You really need to surround the code you want to time in some kind of time measuring mechanism. Something like this:
1 2 3 4 5 6 7 8 9
|
int main()
{
start_timer();
// .. the code you want to time
stop_timer();
}
|
Use whatever timer you want, but a high frequency timer would be more precise and reliable. If you have C++11, the <chrono> header probably has timers you can use. I'd have to research it myself =x
Also, based on the very small snapshot of the compiler options in that image... I do not see optimizations enabled. You
absolutely must enable optimizations to do any kind of benchmarking or your numbers will be completely unrealistic.
Many IDEs come with 2 premade "configurations" called 'Debug' and 'Release'. I think C::B has this as well. Make sure you switch it to Release and rebuild. That will enable optimizations.
EDIT:
Also... you really need to run the code
many, many, many times. Like at
least several thousand. Just running it once will be so fast that the time it takes will be way too small to measure with any kind of precision. So really, something like this would be better:
1 2 3 4 5 6 7 8 9 10 11
|
int main()
{
start_timer();
for(int i = 0; i < 10000; ++i)
{
// ... code you want to time
}
stop_timer();
// divide the time taken by 10000 to find out how long 1 iteration takes on average.
|
when I use the inline function, it gets recursive in my compiler, I think the compiler is ignoring the command or what? |
If you don't have optimizations turned on, it's
definitely ignoring the command.
I suppose the compiler might be able to inline a recursive function if you're calling it with a constant (which you are in this case), so I might have been wrong when I said you couldn't do that.
ANOTHER EDIT:
Also, since you're not using the output of your factorial code, it's possible the compiler will optimize it away completely, resulting in your time measurement being practically 0.
you are using the output. Nevermind. Still, with heavy inlining and optimizations it's very possible the compiler will optimize this:
into this:
In which case the only thing you'd be measuring is cout speed and not factorial speed.