Skip to content

Instantly share code, notes, and snippets.

@rubikill
Last active August 2, 2018 15:51
Show Gist options
  • Save rubikill/7ec1211463e32b9e064f2208074220ca to your computer and use it in GitHub Desktop.
Save rubikill/7ec1211463e32b9e064f2208074220ca to your computer and use it in GitHub Desktop.
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