Following Tim's comments here is the new benchmark. (I'll address the
buffering issue in another post)
use Benchmark;
use Symbol;
my $fh = gensym;
open $fh, ">/dev/null" or die;
sub multi_print{
print $fh "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">";
print $fh "<HTML>";
print $fh " <HEAD>";
print $fh " <TITLE>";
print $fh " Test page";
print $fh " </TITLE>";
print $fh " </HEAD>";
print $fh " <BODY BGCOLOR=\"black\" TEXT=\"white\">";
print $fh " <H1> ";
print $fh " Test page ";
print $fh " </H1>";
print $fh " <A HREF=\"foo.html\">foo</A>";
print $fh " <HR>";
print $fh " </BODY>";
print $fh "</HTML>";
}
sub single_print{
print $fh qq{<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>
Test page
</TITLE>
</HEAD>
<BODY BGCOLOR="black" TEXT="white">
<H1>
Test page
</H1>
<A HREF="foo.html">foo</A>
<HR>
</BODY>
</HTML>
};
}
sub here_print{
print $fh <<__EOT__;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>
Test page
</TITLE>
</HEAD>
<BODY BGCOLOR="black" TEXT="white">
<H1>
Test page
</H1>
<A HREF="foo.html">foo</A>
<HR>
</BODY>
</HTML>
__EOT__
}
sub list_print{
print $fh "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">",
"<HTML>",
" <HEAD>",
" <TITLE>",
" Test page",
" </TITLE>",
" </HEAD>",
" <BODY BGCOLOR=\"black\" TEXT=\"white\">",
" <H1> ",
" Test page ",
" </H1>",
" <A HREF=\"foo.html\">foo</A>",
" <HR>",
" </BODY>",
"</HTML>";
}
timethese
(500_000, {
list_print => \&list_print,
multi_print => \&multi_print,
single_print => \&single_print,
here_print => \&here_print,
});
And the results are:
single_print: 1 wallclock secs ( 1.74 usr + 0.05 sys = 1.79 CPU)
here_print: 3 wallclock secs ( 1.79 usr + 0.07 sys = 1.86 CPU)
list_print: 7 wallclock secs ( 6.57 usr + 0.01 sys = 6.58 CPU)
multi_print: 10 wallclock secs (10.72 usr + 0.03 sys = 10.75 CPU)
Numbers tell it all, I<'single_print'> is the fastest, 'here_print' is
almost of the same speed, I<'list_print'> is quite slow and
I<'multi_print'> is the slowest.
If we run the same benchmark using the unbuffered prints by changing
the beginning of the code to:
use Symbol;
my $fh = gensym;
open $fh, ">/dev/null" or die;
# make all the calls unbuffered
my $oldfh = select($fh);
$| = 1;
select($oldfh);
And the results are:
single_print: 4 wallclock secs ( 2.28 usr + 0.47 sys = 2.75 CPU)
here_print: 2 wallclock secs ( 2.45 usr + 0.45 sys = 2.90 CPU)
list_print: 7 wallclock secs ( 7.17 usr + 0.45 sys = 7.62 CPU)
multi_print: 23 wallclock secs (17.52 usr + 5.72 sys = 23.24 CPU)
The results are worse by the factor of 1.5 to 2, with only
I<'list_print'> changed by very little.
So if you want a better performance, you know what technique to use.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://perl.org http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org