Files
nulsl-libc/benchmarks/bench_syscall.c
T
huntedbytheirsandSisyphus 370e64c3a6 Add smoke test and benchmarks
smoke links crt0.o + libc.a with -nostdlib -static and proves the whole chain runs without the dynamic linker; bench_strlen and bench_syscall measure the string core and raw syscall round-trip cost via make bench.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
2026-08-30 04:09:45 -04:00

30 lines
703 B
C

/*
* bench_syscall.c — raw syscall round-trip cost.
*
* This is the number that justifies the whole project: for a kernel-first
* libc (project guideline #6), every wrapper is one `syscall` instruction
* away from the kernel. getpid() is the cheapest syscall there is, so
* this measures the floor. 1M iterations; results in ns per call.
*/
#include <unistd.h>
#include "bench.h"
#define ITERS 1000000UL
int main(void)
{
volatile pid_t sink = 0;
long long t0, t1;
t0 = bench_now_ns();
for (unsigned long i = 0; i < ITERS; i++)
sink += getpid();
t1 = bench_now_ns();
(void)sink;
bench_print_u64((unsigned long long)((t1 - t0) / ITERS));
return 0;
}