Created
November 14, 2011 09:09
-
-
Save iboB/1363574 to your computer and use it in GitHub Desktop.
simple ruby timer (for simple programs)
This file contains 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
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