/* * Benchmark harness for vlibc (musts/BENCHMARKING.md). * * Every vlibc component is benchmarked against the software it replaces. * This stub times vlibc_version() and is the skeleton that per-component * benchmarks build on. Reconfigure with --with-libc=musl or --with-libc=glibc * to link the same harness against a reference libc for comparison. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #define ITERATIONS 100000000ULL int main(void) { volatile const char *version = NULL; struct timespec start; struct timespec end; double whole; double frac; double seconds; if (clock_gettime(CLOCK_MONOTONIC, &start) != 0) { return 1; } for (unsigned long long i = 0; i < ITERATIONS; i++) { version = vlibc_version(); } if (clock_gettime(CLOCK_MONOTONIC, &end) != 0) { return 1; } whole = (double)(end.tv_sec - start.tv_sec); frac = (double)(end.tv_nsec - start.tv_nsec) / 1000000000.0; seconds = whole + frac; printf("vlibc_version() x %llu: %.3f s (%.2f ns/call), version=%s\n", ITERATIONS, seconds, seconds * 1000000000.0 / ITERATIONS, (const char *)version); return 0; }