Timing Routines for UNIX/Win32

Here is a timing routine library for use with programming assignment 2. Note that you are not required to use this library; it is just provided here for convenience.
For intel solaris machine, here is the precompiled library.

Unix/Linux

For most unix variants, compilation is quite straightforward. Just follow the instruction in the INSTALL and README documents. The following is a quick way to get going.

  1. gunzip ipm-2.0a.tar.gz
  2. tar -xvf ipm-2.0a.tar
  3. cd ipm-2.0a
  4. ./configure
  5. gmake

When compiling your programs, you must load the ipm library. For example

gcc -O3 -o main main.c ../ipm-2.0a/libipm.a
Note that you need to specify the path to the IPM library with -L option.

There following are the routines that might prove useful.

void IPM_timer_clear(IPM_timer *); // resets timer

void IPM_timer_start(IPM_timer *); // starts timer

void IPM_timer_stop(IPM_timer *); // ends timer

// prints out the elapsed time.
void IPM_timer_report(const char *tag, const IPM_timer *, char *buf);

// reads the elapsed time in seconds.
double IPM_timer_report(const IPM_timer *);
More detailed explanation are available in the README file.

Sample code. The following code measures the time spent by the routine foo(). (Excerpt from the README).

#include "IPM_timer.h"    /* Get timer declarations */

extern void foo();    /* function to be timed. */

int main() {
  IPM_timer t;    /* Place for timer info. */
  char report[IPM_TIMER_REPORT_LEN+3];    /* Place to put timer report. */

  IPM_timer_clear(&t);    /* Initialize interval statistics. */

  IPM_timer_start(&t);    /* Start measurement. */
  foo();    /* Routine to be measured. */
  IPM_timer_stop(&t);    /* Stop measurement. */

  IPM_timer_report("foo", &t, report);    /* Format report string. */

  puts(report);    /* Output report string. */

  return 0;
}

Win32

Unfortunately under Windows, the provided code compiles only with Microsoft C/C++ compiler, such as Visual C++, due to some assembly code. You can follow the instruction to setup up here. Of course, with care, you can use the standard GNU gcc port for Win32, and call gettimeofday or some such timing routines.
Win32 Port provided by Rich Vuduc.