i am measuring physical time between two events like this:

```
#include <time.h>
#include <sys/time.h>

timeval wall_time0;
timeval wall_time1;

// start of period measurement
gettimeofday( &wall_time0 , 0);

...stuff happening 

// end of period measurement
gettimeofday( &wall_time1 , 0);

return ( ( wall_time1.tv_sec - wall_time0.tv_sec ) + (( wall_time1.tv_usec - wall_time0.tv_usec )/(double)1000000) );

```

But now, i need a way to measure the logical time that the thread is actually using. That is, in theory that should be the physical time, less the time spent running other threads and/or system & kernel logic.

I *thought* this was the way to do it:

```
clock_t mTime0;
clock_t mTime1;

//start of period measurement
mTime0=clock();

... stuff happening

//end of period measurement
mTime1=clock();
return (mTime1-mTime0)/(double)CLOCKS_PER_SEC;

```

but doing a few measurements, i noticed two problems:

1) for some measurements it is *bigger* than physical time, which is not right (i.e: for certain loop, physical time would be 0.2495.. and "logical" (measured with clock()) would be 0.27, for smaller measurements it would just round up to zero, which leads to the second issue...)

2) the resulting time seems to be a lot coarser than the one return by gettimeofday

is there a better way to measure local thread time in linux?