Skip to content

Instantly share code, notes, and snippets.

@MatteoRagni
Created June 2, 2016 16:27
Show Gist options
  • Save MatteoRagni/07061ba06990bf18a19d654c9ccab751 to your computer and use it in GitHub Desktop.
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
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