I read your question different from my esteemed fellow monks. I think you don't want to just substract the start and end time from your script. I think you want to do two independent things: Regarding the latter you should read CGI progress indicator which contains more links to more resources for this problem.

To solve the first you must be aware how the problem can be split in "units" (lines of csv-file*, records of a fixed-length file/database query or one solution in a shuffle of n numbers, etc.) and how many "units" there are. If that number is undetermina(te|ble) or the processing time per "unit" varies widely, it's hard to predict the runtime reliably.

The main algorithm is relatively simple:
remember starttime determine total_number_of_units loop as long there is a unit to process process unit calculate elapsed time calculate average of elapsed time per unit multiply average with total number of units #this gets the predicted + runtime end loop
I leave it to you to translate that to Perl, since you gave us no code to work with.

Update:

* In the case of a CSV file the number of lines is usually unknown, so it makes sense to use a Byte as a "unit" and to sum up the bytes read to calculate the average.


holli, /regexed monk/

In reply to Re: calculate the time taken to run a script by holli
in thread calculate the time taken to run a script by rsennat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.