Jazzez · Ruby

Computation time in Ruby

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

Advertisements

2 thoughts on “Computation time in Ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s