Created
June 2, 2016 16:27
-
-
Save MatteoRagni/07061ba06990bf18a19d654c9ccab751 to your computer and use it in GitHub Desktop.
A simple tic toc timer in ruby. Timed operations are wrapped in a proc
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 tictoc | |
tic = Time.now | |
yield | |
toc = Time.now | |
ret = toc - tic | |
puts "Time elapsed #{'%.3f' % ret}" | |
return ret | |
end | |
# How to use it? | |
if $0 == __FILE__ | |
ret = tictoc do | |
print "do something..." | |
gets | |
end | |
puts ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment