// KMB 2004 Oct 19
// measure time of user process
// gcc -Wall try_times.c -lm && a.out
// mcopy -o try_times.c a:
//
//clock_t times(struct tms *buf);
//  The times() function stores the current process times in the struct tms
//  that buf points to.  The struct tms is as defined in <sys/times.h>:
//  struct tms {
//    clock_t tms_utime;  /* user time */
//    clock_t tms_stime;  /* system time */
//    clock_t tms_cutime; /* user time of children */
//    clock_t tms_cstime; /* system time of children */
//  };
//  long sysconf(int name);

#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <math.h>

int main() {
  long tps=sysconf(_SC_CLK_TCK); // ticks per second
  struct tms t;
  clock_t t0,t1;
  int i;
  double x;
  printf("%ld ticks per second\n",tps);
  times(&t); t0=t.tms_utime; printf("start: t0=%ld\n",t0);
  for (i=0; i<1000000; i++) x=sin(i);
  times(&t); t1=t.tms_utime; printf("end: t1=%ld\n",t1);
  printf("%f seconds user time elapsed\n",(double)(t1-t0)/tps);
  return 0;
}
