So, I'd like to see how long a function of in my code takes to run. (in realtime). Originally, I had this:
clock_t begin = clock();
my_function();
clock_t end = clock();
double time_spent = (double)(end - begin);
But apparently, there are some problems with this approach.
- It only measures the time that the cpu took to process my application.
- It only measures on microsecond level, from what I can see - which isn't precise enough for my case.
So, what is the proper way to get the time a function took to run? Is CPU time really the right approach? How precise can I measure? I was thinking nanosecond level?