Created
February 8, 2014 18:57
-
-
Save d0rc/8888358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(2)> Test.test1 | |
{1474377, :ok} | |
iex(3)> Test.test2 | |
{755840, :ok} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Awesome! :)