Skip to content

Instantly share code, notes, and snippets.

@IceDragon200
Created October 9, 2020 00:07
Show Gist options
  • Save IceDragon200/978c548f73172645ee25121168066b93 to your computer and use it in GitHub Desktop.
Save IceDragon200/978c548f73172645ee25121168066b93 to your computer and use it in GitHub Desktop.
A small elixir script for bench marking the startup times of applications, specify the top-level app and this will print the slowest application in the tree
excluded = [:stdlib, :kernel, :compiler]
bench_startup = fn bench_startup, acc, app ->
if acc[app] do
acc
else
apps = Application.spec(app, :applications) -- excluded
inc_apps = Application.spec(app, :included_applications) -- excluded
all_apps = apps ++ inc_apps
acc =
Enum.reduce(all_apps, acc, fn app_name, acc ->
bench_startup.(bench_startup, acc, app_name)
end)
{elapsed, _value} = :timer.tc(fn ->
Application.ensure_all_started(app)
end)
Map.put(acc, app, elapsed)
end
end
times_by_app = bench_startup.(bench_startup, %{}, :your_app_name)
apps_by_startup =
Enum.sort_by(times_by_app, fn {_app, time} ->
time
end)
Enum.each(Enum.reverse(apps_by_startup), fn {app, time} ->
IO.puts "#{app}: #{time/1000}ms"
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment