Skip to content

Instantly share code, notes, and snippets.

@mmmries
Created February 28, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmries/c309f3fa5741ed4f6c1b274f876286c1 to your computer and use it in GitHub Desktop.
Save mmmries/c309f3fa5741ed4f6c1b274f876286c1 to your computer and use it in GitHub Desktop.
Quick benchmark tool for Elixir
quick_benchmark = fn(tcfn, tcn) ->
tc_l = :lists.seq(1,tcn) |> Enum.map(fn(_)-> tcfn |> :timer.tc |> elem(0) end)
tc_min = :lists.min(tc_l)
tc_max = :lists.max(tc_l)
tc_med = :lists.nth(round((tcn - 1) / 2), :lists.sort(tc_l))
tc_avg = round(Enum.sum(tc_l) / tcn)
%{min: tc_min, max: tc_max, median: tc_med, average: tc_avg}
end
# quick_benchmark.(fn() -> do_some_work() end, 1000) will do 1000 iterations of work and report median, average, min and max back to you in microseconds
# inspired by http://www2.erlangcentral.org/wiki/?title=Measuring_Function_Execution_Time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment