Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to time the duration of a script.

Reply
Thread Tools

How to time the duration of a script.

 
 
Oscar Gonzalez
Guest
Posts: n/a
 
      12-12-2005
If I wanted to find something like the "time" feature on shell...

where you can do:

time ls

and it will tell you how long it took to execute...

How would I do this in Ruby or what is the packaged that can do this for
me? I want it to kick off as soon as the script gets called and just
print the time taken to execute at the end of the script.

--
Posted via http://www.ruby-forum.com/.


 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      12-12-2005
On Tue, 13 Dec 2005, Oscar Gonzalez wrote:

> If I wanted to find something like the "time" feature on shell...
>
> where you can do:
>
> time ls
>
> and it will tell you how long it took to execute...
>
> How would I do this in Ruby or what is the packaged that can do this for
> me? I want it to kick off as soon as the script gets called and just
> print the time taken to execute at the end of the script.


harp:~ > cat elapsed.rb
BEGIN{ $start_time = Time::now.to_f }
END{ $end_time = Time::now.to_f; puts "#{ $0 } elapsed: #{ $end_time - $start_time} }" }

harp:~ > cat a.rb
sleep 2 and p 42

harp:~ > ruby -r elapsed a.rb
42
a.rb elapsed: 1.99891686439514 }

or

harp:~ > cat a.rb
#!/usr/bin/env ruby
sleep 2 and p 42

harp:~ > RUBYOPT="-relapsed" ./a.rb
42
./a.rb elapsed: 1.99908494949341 }

hth.

-a
--
================================================== =============================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy. all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
================================================== =============================



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Using a time duration to print out data where every 2 seconds is a pixel cjt22@bath.ac.uk Python 9 09-11-2007 08:08 AM
Time lapse duration on Nikon D2Hs battery? DeanB Digital Photography 0 07-10-2007 07:30 AM
OutputCache Duration across time zones? CJ ASP .Net 2 01-06-2006 04:59 PM
What is the Time Duration of all MCSD.net Exams? IMRAN SAROIA MCSD 0 04-04-2004 08:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57