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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|