After seeing this topic, I couldn’t help settings this up →
The code just queries the timer but basically does nothing else. Sample output:
zig build bench-noop --release=fast && ./zig-out/bin/bench-noop
noop!, n=10, avg: 16, std: 8
noop!, n=100, avg: 12, std: 1
noop!, n=1000, avg: 14, std: 4
noop!, n=10000, avg: 15, std: 10
noop!, n=100000, avg: 14, std: 6
noop!, n=1000000, avg: 13, std: 25
I originally stumbled across this while looking at an issue on zbench. I’m not 100% sure how meaningful that is, but the results vary quite drastically if you run this multiple times (at least on my Linux machine). Also, standard deviations tend to outnumber the average at higher N, which is …not a good sign.