Skip to content

Instantly share code, notes, and snippets.

@geofflane
Created March 15, 2017 14:28
Show Gist options
  • Save geofflane/a1467259b11940dde8594dc79f65b06f to your computer and use it in GitHub Desktop.
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.
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