Skip to content

Instantly share code, notes, and snippets.

@TikiTDO
Last active December 12, 2015 13:39
Show Gist options
  • Save TikiTDO/4780145 to your computer and use it in GitHub Desktop.
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.
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