Skip to content

Instantly share code, notes, and snippets.

@leifg
Created May 17, 2017 07:59
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 leifg/fca34d7140d9f0818595318248ab5373 to your computer and use it in GitHub Desktop.
Save leifg/fca34d7140d9f0818595318248ab5373 to your computer and use it in GitHub Desktop.
list = Enum.to_list(1..100_000)
Benchee.run(%{
"List.last" => fn -> list |> List.last end,
"Enum.reverse |> hd" => fn -> list |> Enum.reverse |> hd end
}, time: 20)
@leifg
Copy link
Author

leifg commented May 17, 2017

Output:

Erlang 19.3
Benchmark suite executing with the following configuration:
warmup: 2.00 s
time: 20.00 s
parallel: 1
inputs: none specified
Estimated total run time: 44.00 s


Benchmarking Enum.reverse |> hd...
Benchmarking List.last...

Name                         ips        average  deviation         median
Enum.reverse |> hd        3.36 K      297.33 μs    ±82.10%      156.00 μs
List.last                 2.03 K      491.56 μs    ±16.85%      465.00 μs

Comparison:
Enum.reverse |> hd        3.36 K
List.last                 2.03 K - 1.65x slower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment