/* tictoc.c -- Matlab style Timing Subroutines Written Sep 1, 2005 by Eric Olson for Mathematics 466 These routine are callable from either C or FORTRAN. Usage in FORTRAN real*8 r ... call tic ...computation... call toc(r) Usage in C double r; ... tic(); ...computation... r=toc(); In both examples r contains seconds of elapsed clock time since the last call to tic. */ #include static double tic_time; void tic() { struct timeval tp; struct timezone tzp; gettimeofday(&tp,&tzp); tic_time=(double) tp.tv_sec + (double) tp.tv_usec * 1.e-6; } void tic_() { tic(); } double toc() { struct timeval tp; struct timezone tzp; gettimeofday(&tp,&tzp); return ((double) tp.tv_sec + (double) tp.tv_usec * 1.e-6)-tic_time; } void toc_(double *r) { *r=toc(); }