Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created March 16, 2016 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcg/fd1bf6d1444e6cee4a40 to your computer and use it in GitHub Desktop.
Save chrismcg/fd1bf6d1444e6cee4a40 to your computer and use it in GitHub Desktop.
Quick elixir benchmark
# 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
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