Benchmarking function (using `@benchmark`) for various input sizes

first of, for loop does not return so this won’t become an array as you’d probably want it to, also you want to use $:

julia> using BenchmarkTools

julia> bs = map([10,100,1000]) do l
           @benchmark rand($l)
       end;

julia> bs
3-element Vector{BenchmarkTools.Trial}:
 71.882 ns
 160.522 ns
 1.100 μs

julia> bs[1]
BenchmarkTools.Trial: 10000 samples with 974 evaluations.
 Range (min … max):  71.882 ns … 644.366 ns  ┊ GC (min … max): 0.00% … 85.38%
 Time  (median):     74.186 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   76.662 ns ±  25.452 ns  ┊ GC (mean ± σ):  1.72% ±  4.54%

   ▃▆██▇▄▁▂▂▁  ▁▁                                              ▂
  ▇███████████████▇▆▇▇▆▃▄▁▃▄▄▃▄▃▃▁▁▁▁▃▁▁▁▁▁▁▃▄▅▆▇▇██▇▆▅▆▅▆▇███ █
  71.9 ns       Histogram: log(frequency) by time       104 ns <

 Memory estimate: 144 bytes, allocs estimate: 1.
1 Like