So there is an exercise that says I should create a program to measure which function is faster,a normal one,or a inline one.
Here's the code:
#include <iostream>
#include <string>
#include <assert.h>
#include <ctime>
using namespace std;
clock_t t;
inline void f1(){
t=clock()-t;
if(t!=0)
cout << "f1 " << t << endl;
}
void f2(){
t=clock()-t;
if(t!=0)
cout <<"f2 " << t << endl;
}
int main() {
for(int i = 0;i<10000;i++){
t=clock();
f1();
}
for(int i = 0;i<10000;i++){
t=clock();
f2();
}
}
The problem is f1 appears 4 times and f2 appears 2 times.As you can see I set the functions so they'll show text only if the time difference is bigger than 0.
Why does the inline function get executed slower?! Shouldn't it be faster?