int main(void) { int c = 2000000; int64_t j, r, t = 0; pthread_mutex_t mtx; pthread_mutex_init(&mtx, NULL); pthread_cond_t cnd; pthread_cond_init(&cnd, NULL); mp_time_init(); for (int i = 0; i < c; i++) { const int delay = rand() / (RAND_MAX / 1e5); r = mp_time_us(); #if TEST_SLEEP mp_sleep_us(delay); #else struct timespec ts = mp_time_us_to_timespec(r + delay); pthread_cond_timedwait(&cnd, &mtx, &ts); #endif j = (mp_time_us() - r) - delay; printf("sleep time: t=%"PRId64" sleep=%8i err=%5i\n", r, delay, (int)j); t += j; } fprintf(stderr, "average error:\t%i\n", (int)(t / c)); return 0; }
int main(void) { mp_time_init(); struct ctx *k = malloc(sizeof(struct ctx)); int64_t s = mp_time_us(); makegauss(k, 6); makeuniform(k); print(k); fsck(k); int64_t l = mp_time_us() - s; printf("time: %f ms\n", l / 1000.0); return 0; }