Try gettimeofday()
:
Standard C Library Functions gettimeofday(3C)
NAME
gettimeofday, settimeofday - get or set the date and time
SYNOPSIS
#include <sys/time.h>
int gettimeofday(struct timeval *tp, void *);
int settimeofday(struct timeval *tp, void *);
DESCRIPTION
The gettimeofday() function gets and the settimeofday()
function sets the system's notion of the current time. The
current time is expressed in elapsed seconds and
microseconds since 00:00 Universal Coordinated Time, January
1, 1970. The resolution of the system clock is hardware
dependent; the time may be updated continuously or in clock
ticks.
Here are some macros that I copied from a benchmar program:
/* copied from mpbench */
#define TIMER_CLEAR (tv1.tv_sec = tv1.tv_usec = tv2.tv_sec = tv2.tv_usec = 0)
#define TIMER_START gettimeofday(&tv1, (struct timezone*)0)
#define TIMER_ELAPSED ((tv2.tv_usec-tv1.tv_usec)+((tv2.tv_sec-tv1.tv_sec)*1000000))
#define TIMER_STOP gettimeofday(&tv2, (struct timezone*)0)
struct timeval tv1,tv2;
....
main()
...
TIMER_CLEAR;
TIMER_START;
/* code to instrument goes here */
...
TIMER_STOP;
printf("# threads, calls, seconds, calls/s\n");
printf("%d,%d,%f,%f\n", omp_get_num_threads(), counter, TIMER_ELAPSED/1000000.0, counter / (TIMER_ELAPSED/1000000.0));
I've used this on Solaris and various flavors of linux (although not Debian).
-j