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:
- calculate the time it takes to finish your script, while the script is running.
- show that time and the current progress to the user in a CGI context
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.