J
Jason Lillywhite
Is there an easy way to display the time it takes to compute any
function from within IRB?
function from within IRB?
Jason said:Is there an easy way to display the time it takes to compute any
function from within IRB?
Is there an easy way to display the time it takes to compute any
function from within IRB?
Chris said:It's not unheard of for people to add something like this to their
irbrc:
def time
start = Time.now
result = yield
puts "Completed in #{Time.now - start} seconds."
result
end
In use:
016:0> time { ('a'*10_000_000).sub(/a+/,'hi') }
Completed in 0.446504 seconds.
"hi"
HTH,
Chris
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.