Next: Using Dec Workstations and Unix Up: Program Listings Previous: time.c

timer.c


/* timer.c - simple example of timing a piece of code */

/* c89 timer.c -o timer */

#include <stdio.h>
#include <sys/types.h>
#include <time.h>

main()
{ int i;
  time_t t1,t2;

  (void) time(&t1);
  
   for (i=1;i<=300;++i) printf("%d %d %d\n",i, i*i, i*i*i);
   
   
   (void) time(&t2);
   
   printf("\nTime to do 300 squares and cubes= %d seconds\n", (int) t2-t1);
}


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994