Created
February 28, 2017 21:29
-
-
Save mmmries/c309f3fa5741ed4f6c1b274f876286c1 to your computer and use it in GitHub Desktop.
Quick benchmark tool for Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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