Last active
February 6, 2017 16:03
-
-
Save ghatighorias/c16e965eb3e384630e7284478a84ab60 to your computer and use it in GitHub Desktop.
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
# 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