On Wed, 7 Jun 2000, Stas Bekman wrote:

> 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.

I think this last line is misleading. The reality is that you're doing
500,000 iterations here. Even for the worst case scenario of multi_print
with no buffering you're managing nearly 22,000 outputs a second. Now
granted, the output isn't exactly of normal size, but I think what it
comes down to is that the way you choose to print is going to make almost
zero difference in any real world mod_perl application. The overhead of
URL parsing, resource location, and actually running your handler is going
to take far more overhead by the looks of things.

Perhaps this section should be (re)moved into a posterity section, for it
seems fairly un-informative to me.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org

Reply via email to