// // eput - Display elapsed time since previous measurement. // Note: EPUT = Events Per Unit Time, i.e., frequency. // // - User supplies event scaling factor (default 1). // - One millisecond resolution (15 ms PC clock granularity). // // 24 Mar 2008 /tvb // #include #include #include char *eput_file = "/tmp/eput.txt"; void main (int argc, char *argv[]) { FILE *f; double now, then, scale, et, eput; double time_stamp (void); char *why; // Get optional arguments. why = "since last call"; if (argc > 1) { why = argv[1]; } scale = 1.0; if (argc > 2) { scale = atof(argv[1]); why = argv[2]; } // Get previous time stamp. then = 0; f = fopen(eput_file, "r"); if (f != NULL) { fscanf(f, "%lf", &then); fclose(f); } // Store current time stamp. now = time_stamp(); f = fopen(eput_file, "w"); if (f != NULL) { fprintf(f, "%.3lf", now); fclose(f); } // Calculate elapsed time (time interval). et = now - then; // Calculate events per unit time (frequency). eput = (et != 0.0) ? 1.0 * scale / et : 0.0; // Display results. printf("%.3lf seconds, %.3lf Hz: %s\n", et, eput, why); } // Get millisecond resolution time stamp. double time_stamp (void) { struct _timeb tb; _ftime(&tb); return tb.time + (double)tb.millitm / 1e3; }