[Ilugc] time

  • From: kums@xxxxxxx (Kumaraguru)
  • Date: Sun Sep 10 00:03:54 2006


priya sridhar wrote:

hi
i would like to print the thread execution time with milli second
 accuracy.. i am not able to find anything relevant in time.h.. can u 
please help



Hi,

ANSI/ISO c standard libraries don't have the capability but the
gettimeofday function defined in <sys/time.h> (POSIX 1003.1-2001)
can help you out.

/******************************************/

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

int main()
{                       
        struct timeval tv;
        gettimeofday(&tv,NULL);
        printf("%d Seconds and %d microseconds have elapsed since the
epoch\n",(int)tv.tv_sec,(int)tv.tv_usec);
        return(0);
}

/******************************************/

lookup 'man gettimeofday' for more details.


Regards
Kumaraguru

--

Other related posts: