Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Measuring the elapsed time

This Ruby code measures how long it takes to display the message "hello world".
def test_method(statement)
  start_time = Time.now
  eval(statement)
  end_time = Time.now
  end_time - start_time
end

statement = "sleep 1.5; puts 'hello world'"
elapsed_time = test_method(statement)
puts "elapsed time : #{elapsed_time}"

output
hello world
elapsed time : 1.499266
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS