Thursday, March 1, 2012

Gettimeofday.c Code To Measure Creation/Termination Time for a Process/Thread

#include
#include
#include

struct timeval start, stop;

float elapsed_time, seconds, useconds;

void start_timer()
{
gettimeofday(&start, NULL);
}

float stop_timer()
{
gettimeofday(&stop, NULL);

seconds = stop.tv_sec - start.tv_sec;
useconds = stop.tv_usec - start.tv_usec;

elapsed_time = ((seconds) + useconds/1000000.0);

return (elapsed_time);

// printf("Elapsed time: %f seconds\n", elapsed_time);

// return 0;
}

0 comments:

Post a Comment