Skip to content

Instantly share code, notes, and snippets.

@hubertlepicki
Forked from obrok/bench.ex
Last active February 8, 2017 13:52
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 hubertlepicki/bc6cf6a324f19b6081ace46d67878423 to your computer and use it in GitHub Desktop.
Save hubertlepicki/bc6cf6a324f19b6081ace46d67878423 to your computer and use it in GitHub Desktop.
defmodule Bench do
def bench do
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, &Kernel.+/2) end) |> IO.inspect
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, fn acc, n -> acc + n end) end) |> IO.inspect
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, &(&1 + &2)) end) |> IO.inspect
nil
end
end
iex(12)> Bench.bench {332678, 50000005000000}
{222853, 50000005000000}
{264541, 50000005000000}
nil
iex(13)> Bench.bench
{340863, 50000005000000}
{225812, 50000005000000}
{272376, 50000005000000}
nil
iex(14)> Bench.bench
{333824, 50000005000000}
{229332, 50000005000000}
{269225, 50000005000000}
nil
iex(15)> Bench.bench
{335361, 50000005000000}
{224914, 50000005000000}
{268593, 50000005000000}
nil
iex(16)> Bench.bench
{341300, 50000005000000}
{226071, 50000005000000}
{267108, 50000005000000}
nil
iex(17)> Bench.bench
{337598, 50000005000000}
{225431, 50000005000000}
{269458, 50000005000000}
nil
iex(18)> Bench.bench
{339762, 50000005000000}
{227337, 50000005000000}
{269084, 50000005000000}
nil
iex(19)> Bench.bench
{338536, 50000005000000}
{225843, 50000005000000}
{269779, 50000005000000}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment