Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

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

Note: UITS will retire Libra in spring 2009. Accounts are available on Quarry, a general-purpose Unix computing environment. For more, see ARCHIVED: About the Libra retirement.

If you need a high resolution timer on the Libra Cluster at Indiana University, 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); }
This is document aqpy in domain all.
Last modified on June 30, 2009.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.