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]>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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 */
|
||||
Reference in New Issue
Block a user