Last active
December 12, 2015 13:39
-
-
Save TikiTDO/4780145 to your computer and use it in GitHub Desktop.
Useful little debug tool to place various time reference points into a program. Useful for coarse profiling when excessive detail is not required.
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_point(name) | |
$time_points ||= {} | |
$time_points[name] = [] if !$time_points.has_key? name | |
$time_points[name] << Time.now | |
end | |
def time_report | |
return if !defined? $time_points | |
report_time = Time.now | |
report = "Since %-30s: %f seconds" | |
$time_points.each do|name, vals| | |
if vals.size == 1 | |
puts report % [name, report_time - vals.first] | |
else | |
vals.each_index {|i| puts report % ["#{name}[#{i}]", report_time - vals[i]]} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment