Using LinuxPerf for small functions

using LinuxPerf

bench = make_bench([LinuxPerf.EventType(:hw, :cycles)])
function f(bench, x)
  enable!(bench)
  x = x+1
  disable!(bench)
  x
end
f(bench, x)
reset!(bench)
f(bench, x)
@show counters(bench)

I get 96 cycles from the above. So probably you just need to change the default bench (which defaults to reasonable_defaults, which are actually a lot of metrics the kernel needs to collect and process) and make sure to only measure within a function.

3 Likes