Computation time in Ruby

March 21, 2009

Computation time in Ruby

code:

def time
start = Time.now
result = yield
puts “Completed in #{Time.now – start} seconds.”
result
end

time {
(‘a’*10_000_000).sub(/a+/,’hi’)
}

output:

>ruby computation.rb
Completed in 1.218 seconds.
>Exit code: 0

For more details http://www.ruby-forum.com/topic/182033

2 Responses to “Computation time in Ruby”

  1. Rowena Says:

    Wow..
    But, how about in rails?

    • raveendran Says:

      You can use this code and display the output in View file(html.erb)


Leave a Reply