Skip to content

Instantly share code, notes, and snippets.

@ghatighorias
Last active February 6, 2017 16:03
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 ghatighorias/c16e965eb3e384630e7284478a84ab60 to your computer and use it in GitHub Desktop.
Save ghatighorias/c16e965eb3e384630e7284478a84ab60 to your computer and use it in GitHub Desktop.
# To avoid making extra gist, I have put all the modules needed for benchfella in this gist.
# Nevertheless, you need to break them in different .exs files
defmodule SmallBench do
use Benchfella
setup_all do
input = %{map_fun: fn(element) -> element + 1 end,
list: Enum.to_list(1..10_000)}
{:ok, input}
end
bench "tail-recursive" do
MyMap.map_tco(bench_context.list, bench_context.map_fun)
end
bench "std-lib map" do
Enum.map(bench_context.list, bench_context.map_fun)
end
bench "body-recursive" do
MyMap.map_body(bench_context.list, bench_context.map_fun)
end
end
defmodule MediumBench do
use Benchfella
setup_all do
input = %{map_fun: fn(element) -> element + 1 end,
list: Enum.to_list(1..100_000)}
{:ok, input}
end
bench "tail-recursive" do
MyMap.map_tco(bench_context.list, bench_context.map_fun)
end
bench "std-lib map" do
Enum.map(bench_context.list, bench_context.map_fun)
end
bench "body-recursive" do
MyMap.map_body(bench_context.list, bench_context.map_fun)
end
end
defmodule BigBench do
use Benchfella
setup_all do
input = %{map_fun: fn(element) -> element + 1 end,
list: Enum.to_list(1..1_000_000)}
{:ok, input}
end
bench "tail-recursive" do
MyMap.map_tco(bench_context.list, bench_context.map_fun)
end
bench "std-lib map" do
Enum.map(bench_context.list, bench_context.map_fun)
end
bench "body-recursive" do
MyMap.map_body(bench_context.list, bench_context.map_fun)
end
end
defmodule VerybigBench do
use Benchfella
setup_all do
input = %{map_fun: fn(element) -> element + 1 end,
list: Enum.to_list(1..5_000_000)}
{:ok, input}
end
bench "tail-recursive" do
MyMap.map_tco(bench_context.list, bench_context.map_fun)
end
bench "std-lib map" do
Enum.map(bench_context.list, bench_context.map_fun)
end
bench "body-recursive" do
MyMap.map_body(bench_context.list, bench_context.map_fun)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment