Last active
July 20, 2022 13:11
-
-
Save aifrak/a3f7b3edbbdf83efddb155b778f62bb4 to your computer and use it in GitHub Desktop.
Calculate average execution time inside IEX without third-part libraries
This file contains hidden or 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
| repeat = 10 | |
| microseconds = 1_000_000 | |
| max_concurrency = System.schedulers_online() | |
| test_func = fn -> :timer.tc(PerfectNumbers, :aliquot_sum, [33_550_335]) |> elem(0) end | |
| recompile && Stream.repeatedly(fn -> test_func end) |> Task.async_stream(fn fun -> fun.() end, timeout: :infinity, ordered: false, max_concurrency: max_concurrency) |> Stream.map(fn {:ok, r} -> r end) |> Enum.take(repeat) |> then(&(Enum.sum(&1) / repeat) / microseconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment