/* * bench.h — tiny shared helpers for nulsl-libc benchmarks. * * Deliberately dependency-free beyond the libc itself: timing goes * through a raw clock_gettime syscall, and numbers are printed with * putchar/write because printf() is still a stub. If you write a new * benchmark, include this and stay this lean. */ #ifndef _NULSL_BENCH_H #define _NULSL_BENCH_H #include #include #define BENCH_CLOCK_MONOTONIC 1 /* Monotonic time in nanoseconds, via raw clock_gettime(2). */ static inline long long bench_now_ns(void) { struct { long tv_sec; long tv_nsec; } t; syscall(SYS_clock_gettime, BENCH_CLOCK_MONOTONIC, &t); return t.tv_sec * 1000000000LL + t.tv_nsec; } /* Print an unsigned integer plus a newline, without printf(). */ static inline void bench_print_u64(unsigned long long v) { char buf[24]; int i = sizeof buf; buf[--i] = '\n'; do { buf[--i] = (char)('0' + v % 10); v /= 10; } while (v); write(STDOUT_FILENO, buf + i, sizeof buf - i); } #endif /* _NULSL_BENCH_H */