I am looking to adding benchmarks to my project. As wall-clock time has a high-variance, I would like to use perf-events to measure cpu-instructions executed instead. This should be much more stable.
However, my testing shows that perf-event are not available for the ubuntu-latest runner:
$ sudo sh -c 'echo 0 >/proc/sys/kernel/perf_event_paranoid' $ perf stat ls || true Cargo.lock Performance counter stats for 'ls': 1.05 msec task-clock # 0.618 CPUs utilized 0 context-switches # 0.000 K/sec 0 cpu-migrations # 0.000 K/sec 107 page-faults # 0.102 M/sec <not supported> cycles <not supported> instructions # sad octocat <not supported> branches <not supported> branch-misses 0.001694797 seconds time elapsed 0.001523000 seconds user 0.000000000 seconds sys
(the above repo contains couple of tries to poke at perf-events)
Is there perhaps some magic config somewhere which I can tweak to fix this? Alternatively, is there perhaps a non-perf based way to measure how many CPU cycles my program spends?