Skip to content

Instantly share code, notes, and snippets.

@iboB
Created November 14, 2011 09:09
Show Gist options
  • Save iboB/1363574 to your computer and use it in GitHub Desktop.
Save iboB/1363574 to your computer and use it in GitHub Desktop.
simple ruby timer (for simple programs)
class Timer
def initialize
ObjectSpace.define_finalizer(self,
self.method(:finalize).to_proc)
@start = Time.new
end
def finalize(id)
p "Time: #{Time.now.to_f - @start.to_f} seconds"
end
end
# usage:
# create a new Timer at the beginning of your program
# it will automatically report the time, the program took to execute
# even with many exit points
timer = Timer.new
10000000.times {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment