Created
March 16, 2016 00:17
-
-
Save chrismcg/fd1bf6d1444e6cee4a40 to your computer and use it in GitHub Desktop.
Quick elixir benchmark
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
# in bench/filter_bench.exs | |
defmodule FilterBench do | |
use Benchfella | |
@map (1..1000) |> Enum.map(fn(idx) -> {idx, Integer.to_string(idx)} end) |> Enum.into(%{}) | |
bench "anonymous function" do | |
Enum.filter(@map, fn {k, _v} -> k > 10 end) | |
end | |
def filter_10({k, _v}), do: k > 10 | |
bench "module function" do | |
Enum.filter(@map, &filter_10/1) | |
end | |
end |
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
chris@gairmi % mix bench | |
Settings: | |
duration: 1.0 s | |
## FilterBench | |
[00:16:12] 1/2: module function | |
[00:16:14] 2/2: anonymous function | |
Finished in 3.31 seconds | |
## FilterBench | |
anonymous function 10000 142.22 µs/op | |
module function 10000 155.62 µs/op |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment