Performance gain by avoiding arguments check is very small (less then 1%).
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Mon Sep 29 20:52:42 GMT 2025
Hi Amit,
Modern compilers will optimize your example code away. You can see that
there are no checks at all in the main function: https://godbolt.org/z/aeeTx6zqM
Even if it wasn't optimized, it wouldn't be possible to measure any difference.
Running an empty main() in a loop will just measure shell overheads. Your
results show it takes a few million cycles per iteration, so an extra check cannot
be measured. What you're really measuring is the varying turbo frequency of
your laptop...
Benchmarking is hard, much harder than you think. It is done by creating a
tight loop around any code you want to measure. You have to use inputs that
are representative of real usage (ideally from traces from actual workloads).
For timing we use a high-resolution (nano-second) timer. You can look at
recent benchmarks in benchtests/ that show how it should be done.
Cheers,
Wilco
More information about the Libc-alpha
mailing list