00001
00002
00005 #include <time.h>
00006 #include <sys/times.h>
00007
00008 static long tps;
00009 static struct tms t;
00010 static clock_t t0,t1;
00011
00013 double timing_init(FILE *f) {
00014 tps=sysconf(_SC_CLK_TCK);
00015 times(&t);
00016 t0=t.tms_utime;
00017 fprintf(f,"start: t0=%.2f seconds\n",t0/(double)tps);
00018 return t0/(double)tps;
00019 }
00020
00022 double timing_end(FILE *f) {
00023 times(&t);
00024 t1=t.tms_utime;
00025 fprintf(f,"end: t1=%.2f seconds\n",t1/(double)tps);
00026 fprintf(f,"%f seconds user time elapsed\n",(double)(t1-t0)/tps);
00027 return (double)(t1-t0)/tps;
00028 }