Re: [log4perl-devel] performance enhancement for timestamps

2010-01-26 Thread Mike Schilli

On Fri, 22 Jan 2010, Rob Retter wrote:


I sent this message a little while ago


Sorry for the delay, thanks for your patience.


In DateFormat.pm, the routine fmt() should not bother to recreate the


This is a neat idea, we just need to change that the mere presence of
the Time::HiRes module introduces milliseconds and hence kills the
optimization.

More to come soon ...

-- Mike

Mike Schilli
m...@perlmeister.com


time string over and over and overYou tend to see the same
timestamp on numerous consecutive log entries (unless you're using
milliseconds, which seems like overkill in many situations).  Anyway,
the code should be something like:

{
my $lastSecs = 0;
my $lastMsecs = 0;
my $lastFmt = '';

###
sub format {
###
    my($self, $secs, $msecs) = @_;

    $msecs = 0 unless defined $msecs;

    return $lastFmt if ($lastSecs == $secs and
    $lastMsecs == $msecs);

    my @time;

    if($GMTIME) {
    @time = gmtime($secs);
    } else {
    @time = localtime($secs);
    }

    # add milliseconds
    push @time, $msecs;

    my @values = ();

    for(@{$self-{stack}}) {
    my($val, $code) = @$_;
    if($code) {
    push @values, $code-($time[$val]);
    } else {
    push @values, $time[$val];
    }
    }

    $lastSecs = $secs;
    $lastMsecs = $msecs;
    $lastFmt = sprintf($self-{fmt}, @values);
    return $lastFmt;
}

}

--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel
--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com___
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel


[log4perl-devel] performance enhancement for timestamps

2010-01-25 Thread Rob Retter
I sent this message a little while ago, but I was not then a member of the 
mailing list.  I got no response and do not see it in the archives, so I can't 
tell if it's awaiting some sort of moderator approval, or it just got tossed 
into the trash.  I've joined the list and am trying again.  I apologize for any 
duplication(s) caused.

--


In DateFormat.pm, the routine fmt() should not bother to recreate the time 
string over and over and overYou tend to see the same timestamp on numerous 
consecutive log entries (unless you're using milliseconds, which seems like 
overkill in many situations).  Anyway, the code should be something like:

{
my $lastSecs = 0;
my $lastMsecs = 0;
my $lastFmt = '';

###
sub format {
###
    my($self, $secs, $msecs) = @_;

    $msecs = 0 unless defined $msecs;

    return $lastFmt if ($lastSecs == $secs and
    $lastMsecs == $msecs);

    my @time;

    if($GMTIME) {
    @time = gmtime($secs);
    } else {
    @time = localtime($secs);
    }

    # add milliseconds
    push @time, $msecs;

    my @values = ();

    for(@{$self-{stack}}) {
    my($val, $code) = @$_;
    if($code) {
    push @values, $code-($time[$val]);
    } else {
    push @values, $time[$val];
    }
    }

    $lastSecs = $secs;
    $lastMsecs = $msecs;
    $lastFmt = sprintf($self-{fmt}, @values);
    return $lastFmt;
}

}

--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel