Skip to content

Instantly share code, notes, and snippets.

@asross
Last active December 21, 2015 04:58
Show Gist options
  • Save asross/6252889 to your computer and use it in GitHub Desktop.
Save asross/6252889 to your computer and use it in GitHub Desktop.
simple profiling
def time(&block)
$breakpoints = []
start = Time.now
yield
puts "----------------\n"
puts "Total time:"
puts "\t#{(Time.now - start).round(1)}s"
puts "Breakdown:"
$breakpoints.each.with_index do |(msg, t), i|
puts "\t#{(t-start).round(1)}s, breakpoint #{i} #{"(#{msg})" if msg}"
end
end
def breakpoint(msg=nil)
$breakpoints << [msg, Time.now]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment