xsl-list
[Top] [All Lists]

Re: [xsl] current-dateTime()

2008-04-18 07:12:28
Andrew Welch schrieb:
I often do:

<xsl:if test="position() mod 1000 eq 0">
  <xsl:message select="concat('Processed ', position(), '/', $total')"/>

to output:

Processed 1000/1000000
Processed 2000/1000000
...

which is good enough to show something is happening but it would've
been nicer to also show an estimated finish time based on progress so
far.

Maybe a little off-topic Perl wrapper will do for you, which allows you
to keep XSL pure while at the same time notifying you when you may get
back to your long-running XSL task:

mludwig(_at_)forelle:~/Werkstatt/xsl > cat timer.pl
use strict;
use warnings;
use Time::HiRes 'time';
my $t0 = time;
while (<>) {
    chomp;
    my($processed, $total) = m#(\d+)/(\d+)#g;
    if (! ($processed and $total) or $processed > $total) {
        warn "problem understanding '$_'\n"; next;
    }
    my $percent = 100.0 * $processed / $total;
    my $time_used = time - $t0;
    my $time_per_item = $time_used / $processed || 1;
    if ($processed == $total) {
        printf "Processed %u/%u in %.2f s, %.5f s per item\n",
            $processed, $total, $time_used, $time_per_item;
        last;
    }
    my $timeleft = $time_per_item * ($total - $processed);
printf "Processed %u/%u in %.2f s, %.2f%%, %.2f s estimated till end\n",
        $processed, $total, $time_used, $percent, $timeleft;
}

mludwig(_at_)forelle:~/Werkstatt/xsl > for t in $(seq 1 10); do sleep 0.3; echo $t/10; done | perl timer.pl
Processed 1/10 in 0.29 s, 10.00%, 2.59 s estimated till end
Processed 2/10 in 0.60 s, 20.00%, 2.38 s estimated till end
Processed 3/10 in 0.90 s, 30.00%, 2.11 s estimated till end
Processed 4/10 in 1.21 s, 40.00%, 1.82 s estimated till end
Processed 5/10 in 1.52 s, 50.00%, 1.52 s estimated till end
Processed 6/10 in 1.83 s, 60.00%, 1.22 s estimated till end
Processed 7/10 in 2.14 s, 70.00%, 0.92 s estimated till end
Processed 8/10 in 2.44 s, 80.00%, 0.61 s estimated till end
Processed 9/10 in 2.76 s, 90.00%, 0.31 s estimated till end
Processed 10/10 in 3.06 s, 0.30617 s per item

Michael

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>