Last active
August 2, 2018 15:51
-
-
Save rubikill/7ec1211463e32b9e064f2208074220ca 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
defmodule App do | |
@x "123" | |
@y "456" | |
@z "789" | |
def fx1 do | |
for _ <- 1..100_000 do | |
"#{@x}#{@y}#{@z}" | |
end | |
end | |
def fx2 do | |
for _ <- 1..100_000 do | |
IO.iodata_to_binary([@x, @y, @z]) | |
end | |
end | |
def fx3 do | |
for _ <- 1..100_000 do | |
@x <> @y <> @z | |
end | |
end | |
def time_of(function, args) do | |
{time, result} = :timer.tc(function, args) | |
IO.puts("Time: #{time}ms") | |
# IO.puts("Result: #{result}") | |
end | |
end | |
App.time_of(&App.fx1/0, []) | |
App.time_of(&App.fx2/0, []) | |
App.time_of(&App.fx3/0, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment