Skip to content

Instantly share code, notes, and snippets.

/ex

Last active May 23, 2016 17:12
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 anonymous/3cf62215407b829da4ab013d111cebfe to your computer and use it in GitHub Desktop.
Save anonymous/3cf62215407b829da4ab013d111cebfe to your computer and use it in GitHub Desktop.
defmodule Calls do
def val1, do: "val1"
def val2, do: "val2"
end
defmodule Constants do
defmacro c name, value do
quote do
defmacro unquote(name) do
unquote(value)
end
end
end
end
defmodule Constants.Vals do
require Constants
Constants.c val1, "val1"
Constants.c val2, "val2"
end
defmodule Profile do
require Constants.Vals
def match v do
case v do
Constants.Vals.val1 -> "matched val1"
Constants.Vals.val2 -> "matched val2"
_ -> "no match"
end
end
def matchcall v do
if (v == Calls.val1) do
"matched val1"
else
if (v == Calls.val2) do
"matched val2"
else
"no match"
end
end
end
def trymatch do
match :nil
match "val1"
match "val2"
match "val3"
end
def trymatchcall do
matchcall :nil
matchcall "val1"
matchcall "val2"
matchcall "val3"
end
end
==============================================================================================
mix profile.fprof -e Profile.trymatchcall
Reading trace data...
End of trace!
Processing data...
Creating output...
Done!
CNT ACC (ms) OWN (ms)
Total 23 0.038 0.037
:fprof.apply_start_stop/4 0 0.038 0.002
anonymous fn/0 in :elixir_compiler_1.__FILE__/1 1 0.035 0.001
Profile.trymatchcall/0 1 0.034 0.004
Profile.matchcall/1 4 0.030 0.011
:error_handler.undefined_function/3 1 0.013 0.003
:error_handler.ensure_loaded/1 1 0.008 0.002
:code.ensure_loaded/1 1 0.005 0.001
:code.call/1 1 0.004 0.001
Calls.val1/0 4 0.004 0.004
:code_server.call/2 1 0.003 0.002
Calls.val2/0 3 0.003 0.003
:fprof."-apply_start_stop/4-after$^0/0-0-"/3 1 0.001 0.001
:erlang.whereis/1 1 0.001 0.001
:erlang.function_exported/3 1 0.001 0.001
:suspend 2 0.001 0.000
:undefined 0 0.000 0.000
==============================================================================================
mix profile.fprof -e Profile.trymatch
Reading trace data...
End of trace!
Processing data...
Creating output...
Done!
CNT ACC (ms) OWN (ms)
Total 8 0.012 0.012
:fprof.apply_start_stop/4 0 0.012 0.002
anonymous fn/0 in :elixir_compiler_1.__FILE__/1 1 0.009 0.001
Profile.trymatch/0 1 0.008 0.004
Profile.match/1 4 0.004 0.004
:fprof."-apply_start_stop/4-after$^0/0-0-"/3 1 0.001 0.001
:undefined 0 0.000 0.000
:suspend 1 0.000 0.000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment