Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

25
Oct

Displaying execution time of a program

Related Blog Items

refer another post for gettimeofday

usage part looks like below
log_time(1);
*block of code*
log_time(2);

 
#include < sys/time.h >
#include < time.h >
/* To start timer,event=1;
To stop timer,event=2*/
 
void log_time(int event)
{
  static struct timeval tv_start;
  struct timeval tv_end;
  struct timeval *tv;
 
  tv = ((event==2)?&tv_end:&tv_start);
 
  gettimeofday(tv, NULL);
 
  if(event==2)
  {
    printf("Time: %ld Seconds %ld Microseconds\n",
           tv_end.tv_sec - tv_start.tv_sec,
           tv_end.tv_usec - tv_start.tv_usec);
  }
}

Popularity: 7%

You need to log on to convert this article into PDF


Related Blog Items

2 Comments

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image