Monday, April 30, 2012

gettimeofday/settimeofday for Making a Function Appear to Take No Time

I've got an auxiliary function that does some operations that are pretty costly.

I'm trying to profile the main section of the algorithm, but this auxiliary function gets called a lot within. Consequently, the measured time takes into account the auxillary function's time.

To solve this, I decided to set and restore the time so that the auxillary function appears to be instantaneous. I defined the following macros:

#define TIME_SAVE struct timeval _time_tv; gettimeofday(&_time_tv,NULL);
#define TIME_RESTORE settimeofday(&_time_tv,NULL);

. . . and used them as the first and last lines of the auxiliary function. For some reason, though, the auxiliary function's overhead is still included!

So, I know this is kind of a messy solution, and so I have since moved on, but I'm still curious as to why this idea didn't work.

Can someone please explain why? Ubuntu 10.04 x86_64.


No comments:

Post a Comment