Indiana University
University Information Technology Services
  
What are archived documents?

On Libra, how do I time different parts of my program?

If you need a high resolution timer on the Libra Cluster, use read_real_time(). For more information, refer to the man page. Following is sample code adapted from the man page:

#include <stdio.h> #include <sys/time.h> int main() { int i; timebasestruct_t start, finish; int val = 3; int secs, n_secs; /* get the time before the operation begins */ read_real_time(&start, TIMEBASE_SZ); /* begin code to be timed */ for (i=0; i<15; i++) (void) printf("This is a sample line %d \n", val); /* end code to be timed */ /* get the time after the operation is complete */ read_real_time(&finish, TIMEBASE_SZ); /* * Call the conversion routines unconditionally, to ensure * that both values are in seconds and nanoseconds regardless * of the hardware platform. */ time_base_to_time(&start, TIMEBASE_SZ); time_base_to_time(&finish, TIMEBASE_SZ); /* subtract the starting time from the ending time */ secs = finish.tb_high - start.tb_high; n_secs = finish.tb_low - start.tb_low; /* * If there was a carry from low-order to high-order during * the measurement, we may have to undo it. */ if (n_secs < 0) { secs--; n_secs += 1000000000; } (void) printf("Sample time was %d seconds %d nanoseconds\n", secs, n_secs); exit(0); }

Also see:

This is document aqpy in domain all.
Last modified on January 15, 2008.
Please tell us, did you find the answer to your question?