Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Time modules

by mikejones (Scribe)
on Feb 24, 2009 at 16:06 UTC ( #746034=perlquestion: print w/replies, xml ) Need Help??

mikejones has asked for the wisdom of the Perl Monks concerning the following question:

All, I want to display the running time it took to complete and estimated time left of a program. I looked into modules Time::Elapse and Time::Progress. Will these suffice? Any recommendations?

Replies are listed 'Best First'.
Re: Time modules
by ELISHEVA (Prior) on Feb 24, 2009 at 16:46 UTC
    Before you can decide what solution is best (and before we can give anything other than vague recommendations), the following questions need to be answered:
    • To estimate time left, you need a way to estimate the total time of the process? How do you plan to do that?
    • If estimated time is proportional to some units (e.g. bytes transfered), what are those unit and how do you measure them?
    • Sometimes initial estimates can be horribly wrong and need to be readjusted. Does this fit your case, and if so, what algorithm will you use to do the readjustment? More specifically, what information does that algorithm rely on? Do you need a solution that will let you adjust the expected time for the process?
    • Does the interface for displaying the time lapsed/time to completion matter? Do you want a GUI interface? Is a line to stdout/stderr enough?

    The tools you have listed do not answer those questions. Time::Elapse provides a simple functional interfaces for lapsed time but does not tell you what time remains. Time::Progress provides an object that tracks lapsed time and compares it to time for completion. It provides some methods for setting and revising estimates, but doesn't do the estimating for you.

    Best, beth

      I think Time::Progress is what I need or something similar. I am playing with it now. To answer your questions, IDK for sure.

      I am using File::Find on some small and some very large filesystems, 30Gb for example. I could use the Unix time binary to give me total time elapsed.

      The units would be the number of files to look at for a specified size in any one filesystem

      I could adjust the expected time, something solid is ideal but "something" is desired, maybe a rough estimate???

      The interface for times lapsed and time to completed is OK to look like

      Elapsed Time: 0:20 min:sec, ########..........................20.0%
      nothing fancy. Does min and max represent seconds here ? $timer->attr( min => 0, max => 100 ).

      Is the for loop here used just for the printing of #s?

      CPAN does not say:

      min This is the min value of the items that will follow (used to calcu +late estimated finish time) max This is the max value of all items in the even (also used to calcu +late estimated finish time)

      use strict ; use warnings ; use File::Find ; use Logfile::Rotate ; use Time::Progress ; $| = 1 ; ###-- autoflush to get \r working --### my $timer = new Time::Progress ; $timer->attr( min => 0, max => 100 ); $timer->restart; print "\n"; for my $incr ( 0 .. 20 ) { ###-- print progress bar and % done --## +# print $timer->report( "Elapsed Time: %L min:sec, %40b %p\r", $incr + ) ; sleep 1 ; } ### MAIN CODE HERE ### <snip> logroll ; ### END OF MAIN CODE ### ###-- stop timer --### $timer->stop ; ###-- report times --### print $timer->elapsed_str ;

      thank you!

        The documentation is very confusing, but between reading the source code and rereading the docs, here's how it works:
        • min is the starting unit, e.g. 0
        • max is the ending unit, e.g. 100 or 1000
        • or in your case, maybe number of files or total number of Gb
        • report($format, $cur) - prints out how much has been done so far using the format $format. $cur is the number of units consumed so far, i.e. the number of files or number of Gb examined so far
        • time estimates are calculated by comparing the lapsed time to $cur/($max - $min) and scaling up appropriately.

        So the usage would be something like:

        1. create a progress object with appropriate min/max
        2. in a loop,
          1. do N units of work
          2. after each N units have been completed, call report($format, $cur) to report how many units have been completed so far

        BTW - I also noted the docs show report like this report(format, [current item]). I'm not quite sure what was intended by that. According to the source code, the call should look like this: report($format, $currentItem)

        Best, beth

Re: Time modules
by poolpi (Hermit) on Feb 24, 2009 at 19:59 UTC

    Your need made me think of something like a progress bar.
    You might have a look at Term::ProgressBar.

    From doc:

    Term::ProgressBar provides a simple progress bar on the terminal, to let the user know that something is happening, roughly how much stuff has been done, and maybe an estimate at how long remains.


    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
Re: Time modules
by dHarry (Abbot) on Feb 25, 2009 at 12:30 UTC

    I'm with poolpi. There is no need to reinvent wheels. This module seems perfect for what you want. Check this node: Term::ProgressBar. Of course it is notoriously difficult to get accurate estimates of the time left so you probably end up with "M$ seconds";-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://746034]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2023-03-26 09:16 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.