Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ruby way to time how long a script takes to run?

Status
Not open for further replies.

Trevoke

Programmer
Jun 6, 2002
1,142
US
I'm trying to use Ruby to measure how long my scripts take to run. Is there a better way than defining two DateTime objects, initializing them as 'now' at the beginning and at the end, and looking at the difference?

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Figured it out.. I wasn't far off I guess..

beginning = Time.now

# code block

puts "Time elapsed: #{Time.now - beginning} seconds."


And voila..

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
You could also check out the Benchmark class for more accurate reporting of what's taking the most time.

-------------------------
Matt Grande
C# Master.
Ruby on Rails Admirer.
ActionScript Student.
JavaScript Hate-Monger.
 
If you use test:unit you'll get these figures automatically when you're carrying out your unit testing.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top