stopwatch.h


R. Clayton (rclayton@monmouth.edu)
(no date)


#ifndef _stopwatch_h_defined_
#define _stopwatch_h_defined_

#include <sys/time.h>

class stopwatch {

  public:

    unsigned elapsed(void) {
      if (begin.tv_sec < end.tv_sec) {
        end.tv_sec++;
        end.tv_usec += 1000000;
        }

      return
        (end.tv_sec - begin.tv_sec)*1000000 + (end.tv_usec - begin.tv_usec);
      }

    void start(void) {
      time(begin);
      }

    void stop(void) {
      time(end);
      }

  private:

    struct timeval begin, end;

    struct timeval time(struct timeval & t) {
      if (gettimeofday(&t, NULL)) {
        perror("gettimeofday() failure");
        exit(EXIT_FAILURE);
        }
      return t;
      }
  };

#endif

// $Log: stopwatch.h,v $
// Revision 1.1 2002/11/29 21:54:26 rclayton
// Initial revision
//



This archive was generated by hypermail 2.0b3 on Mon Dec 15 2003 - 19:45:05 EST