/* ex: set ts=2 et: */ #include #include #include #include #include #include #define N_TIMES 2000 static void speed(const char *name, const char *(*f)(unsigned, char *, size_t)) { double d[2]; /* test speed */ i = N_TIMES; gettimeofday(tv, NULL); do f(); while (i--); gettimeofday(tv + 1, NULL); d[0] = (tv[0].tv_sec * 1000000) + tv[0].tv_usec; d[1] = (tv[1].tv_sec * 1000000) + tv[1].tv_usec; fprintf(stderr, " %.3f secs\n", (d[1] - d[0]) / 1000000); } inline static int lcg(void) { static int seed = 42; return max * ((seed = (seed * IA + IC) % IM) * (1.0 / IM)); }