Skip to content

Instantly share code, notes, and snippets.

@d0rc
Created February 8, 2014 18:57
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 d0rc/8888358 to your computer and use it in GitHub Desktop.
Save d0rc/8888358 to your computer and use it in GitHub Desktop.
iex(2)> Test.test1
{1474377, :ok}
iex(3)> Test.test2
{755840, :ok}
defmodule Test do
defp regexp(url) do
if String.match? url, ~r/^hello, / do
url <> "world"
else
url
end
end
defp better(url) do
case String.downcase(url) do
<<"hello, "::utf8, _::binary>> -> url <> "world"
_ -> url
end
end
def test1 do
:timer.tc fn ->
Enum.each 1..1000000, fn _ -> regexp("hello, ") end
end
end
def test2 do
:timer.tc fn ->
Enum.each 1..1000000, fn _ -> better("hello, ") end
end
end
end
@edgurgel
Copy link

edgurgel commented Feb 8, 2014

Awesome! :)

@d0rc
Copy link
Author

d0rc commented Feb 8, 2014

Hope it will convince you to merge the pull request before 0.12.4 available:)

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