Skip to content

Instantly share code, notes, and snippets.

@michalmuskala
Created March 30, 2018 19:37
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 michalmuskala/35ba70cec520e704233993cc4c575141 to your computer and use it in GitHub Desktop.
Save michalmuskala/35ba70cec520e704233993cc4c575141 to your computer and use it in GitHub Desktop.
defmodule Bench do
@binary String.duplicate("a", 1024)
@list String.to_charlist(@binary)
def binary_utf8(), do: binary_utf8(@binary)
defp binary_utf8(<<_::utf8, rest::bits>>), do: binary_utf8(rest)
defp binary_utf8(<<>>), do: :ok
def binary_byte(), do: binary_byte(@binary)
defp binary_byte(<<_, rest::bits>>), do: binary_byte(rest)
defp binary_byte(<<>>), do: :ok
def list(), do: list(@list)
defp list([_ | rest]), do: list(rest)
defp list([]), do: :ok
end
Benchee.run(%{
"binary_utf8" => &Bench.binary_utf8/0,
"binary_byte" => &Bench.binary_byte/0,
"list" => &Bench.list/0
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment