Jul 21
First, tic() and toc() functions. These work like Matlab: tic() starts the timer, and toc() stops it and gives formatted output. There’s also a tocq() function which just returns the number of elapsed seconds.
#include <time.h> static clock_t tic_timestart; void tic(void) { tic_timestart = clock(); } float toc(void) { clock_t tic_timestop; tic_timestop = clock(); printf("time: %8.2f.\n", (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC); return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC; } float tocq(void) { clock_t tic_timestop; tic_timestop = clock(); return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC; }
A bit of code for counting flops: first, a statistics structure, then some defines.
/* CFDIV divides 1/a[3] * CFADD adds c[12] + d[12] * CFMUL multiplies b[4] * h[7] * CFASN assigns A[5] = 0 * CFSTO stores A[5] = (...) * CFTFR transfers A[5] = b[7] * CFNTF negated transfers A[5] = -b[7] * CFCOM compares c[5] < b[7] */ typedef struct statistics_t *statistics; typedef struct statistics_t { long div; long add; long mul; long asn; long sto; long tfr; long ntf; long com; } Statistics;