Created
March 15, 2017 14:28
-
-
Save geofflane/a1467259b11940dde8594dc79f65b06f to your computer and use it in GitHub Desktop.
Elixir function that can be used to wrap a function to log the amount of time it takes to execute. Good for profiling in development.
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.Timer do | |
require Logger | |
def log(name, fun) do | |
{time, result} = :timer.tc(fun) | |
Logger.error("#{name}: #{time / 1000}ms") | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment