in reply to Re: Optimizing the bejeezus out of a sub
in thread Optimizing the bejeezus out of a sub
I wrote about the C-style for() in Re: Re: Believably slow... It is slower than the foreach() style for. Not significantly but slightly. I could only remove a few operations from your code, I noted each spot with an ALTER comment. I think your time is consumed by those print() statement - IO is always expensive.
## Print the given template sections to the supplied filehandle sub printto { my $self = shift; my $fh = shift; my $ret = 0; my($val,$sec,$v); # ALTER - foreach over C-style for foreach my $sec_k (@_) { $sec = $self->[_sec]{$sec_k}; # ALTER - drop unnecessary defined() unless ( $sec ) { # ALTER - remove indirect object syntax $fh->print( $self->_nosuchsec($sec_k) ); next; } $ret++; foreach $v (@$sec) { if ($v->[_type] == type_text) { # ALTER - remove indirect object syntax $fh->print( $v->[_contents] ); } else { $val = $self->[_assign]{$v->[_contents]}; $fh->print( defined $val ? $val : $self->_nosuchvar($val,"\$".$val) ); } } } return $ret; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Optimizing the bejeezus out of a sub
by sgifford (Prior) on Jun 24, 2003 at 16:23 UTC | |
by diotalevi (Canon) on Jun 24, 2003 at 16:35 UTC | |
by sgifford (Prior) on Jun 24, 2003 at 16:47 UTC | |
by diotalevi (Canon) on Jun 24, 2003 at 16:57 UTC | |
by sgifford (Prior) on Jun 24, 2003 at 17:03 UTC | |
|