Comparing benchmarks

Assume two functions f and g whose relative performance
I would like to determine.

@time f(100) -> f_sec (f_alloc: f_mem)
@time g(100) -> g_sec (f_alloc: f_mem)

I would like to have a macro which gives me

@relperf f(100), g(100) -> (f_sec/g_sec, f_alloc/g_alloc, f_mem/g_mem)

It is beyond my knowledge to write such a macro.
Maybe someone is willing to give it away?

BenchmarkTools.jl!
The link points to the ratio and judge functions in the docs.

1 Like

Have you seen the @timed macro?

help?> @timed
  @timed

  A macro to execute an expression, and return the value of the expression,
  elapsed time, total bytes allocated, garbage collection time, and an object
  with various memory allocation counters.

  See also @time, @timev, @elapsed, and @allocated.

  julia> val, t, bytes, gctime, memallocs = @timed rand(10^6);
  
  julia> t
  0.006634834
  
  julia> bytes
  8000256
  
  julia> gctime
  0.0055765
  
  julia> fieldnames(typeof(memallocs))
  9-element Array{Symbol,1}:
   :allocd
   :malloc
   :realloc
   :poolalloc
   :bigalloc
   :freecall
   :total_time
   :pause
   :full_sweep
  
  julia> memallocs.total_time
  5576500

Edit I just saw what Elrod wrote, lol. Definitely use BenchmarkTools for more accurate benchmarks, because they deal with warm up time and they average times as well.