Using perf-stat as a simple benchmark wrapper
I'm pretty familiar with most of the options available to the perf-stat
command but I've never understood why anyone would want to use the --null
option. The help text for this option reads,
-n, --null null run - dont start any counters
Then I came across this commit to the Linux kernel tree from Peter Zijlstra and it suddenly became clear that --null
allows you to use the other features of perf-stat
, such as its ability to repeatedly execute a command via --repeat
, without the overhead incurred from using performance counters.
In short, you can use perf-stat
as a simple benchmark wrapper or harness to execute a program and print runtime statistics.
For example, if you've got a micro-benchmark that executes some operations and you care about the time it took to perform those operations (as opposed to the number of operations), you can use perf-stat
to run the program a number of times and print the average (arithmetic mean) time it took to run the program along with the coefficient of variance,