Last active
December 21, 2015 04:58
-
-
Save asross/6252889 to your computer and use it in GitHub Desktop.
simple profiling
This file contains hidden or 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
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