I remember reading something about the way output is handled in ASP that
said it's best not to use something like

$html = "<html>\n"
$html = "<table border=\"2\">"
while (!$rs->EOF) {
    $html .= "<tr><td>" . $rs->Fields("whatever")->Value
    $rs->MoveNext
}

$Response->Write($html)

Because repeatedly contatinating large strings like that is really expensive
processor-wise, whereas using $Response->Write just appends whatever you
pass it to the end of the output buffer, assuming you have buffering turned
on, and is less processor intensive.  Never written a script to test it
though.

josh



----- Original Message -----
From: "Ron Grabowski" <[EMAIL PROTECTED]>
To: "Matthew Thompson" <[EMAIL PROTECTED]>; "Perl Web (E-mail)"
<[EMAIL PROTECTED]>
Sent: Tuesday, June 26, 2001 10:48 AM
Subject: Re: effiency in string formatting???


> > Is that more efficient than this
>
> I doubt even an inefficient small loop like this will have a drastic
impact
> on the rest of your program.
>
> > 'print "$name";' different from 'print $name;' and the later is more
> > efficient (I think).
>
> Mastering Algorithms with Perl has a little footnote in the first couple
> pages saying that the print($name, $name2, $name) is about 20%(?) faster
> than other versions of print.
>
> In this case I'd probably do 'Ron2'. I think its more common in other
> languages to concatenate strings together then print them out ( this is
the
> suggested way for VBScript in ASP since multiple calls to Response.Write()
> are expensive ).
>
> ---
> use Benchmark;
>
> @users = qw| a:b:c d:e:f g:h:i j:k:l |;
>
> close STDERR;
>
>  timethese(100_000, {
>
>      'Orig1' =>
>    sub {
>
>      $html="start of html code";
>
>      foreach $_ (@users) {
>        chomp($_);
>        ($name, $pass, $privelages) = split(/:/, $_);
>        $html.="<TR><TD><INPUT TYPE=\"radio\" NAME=\"user\" VALUE=\"";
>        $html.=$name;
>        $html.="\"></TD>\n<TD>\n";
>        $html.=$name;
>        $html.="</TD><TD>";
>        $html.=$privelages;
>        $html.="</TD></TR>\n";
>      }
>      $html.="rest of html code";
>
>    },
>
>      'Orig2' =>
>
>     sub {
>
>       $html="start of html code";
>
>       foreach $_ (@users) {
>         chomp($_);
>         ($name, $pass, $privelages) = split(/:/, $_);
>         $html.="<TR><TD><INPUT TYPE=\"radio\"
>
NAME=\"user\"VALUE=\"$name\"></TD>\n<TD>\n$name</TD><TD>$privelages</TD></TR
> >\n";
>       }
>
>     },
>
>      'Ron' =>
>     sub {
>
>       $html="start of html code";
>
>       foreach (@users) {
>         chomp;
>         my($name,$pass,$privelages) = split /:/ ;
>         $html.=qq|<TR><TD><INPUT TYPE="radio" NAME="user"
> VALUE="$name"></TD>\n<TD>\n$name</TD><TD>$privelages</TD></TR>\n|;
>       }
>
>     },
>
>      'Ron2' =>
>     sub {
>
>       foreach (@users) {
>         chomp;
>         my($name,$pass,$privelages) = split /:/ ;
>         print STDERR qq|<TR><TD><INPUT TYPE="radio" NAME="user"
> VALUE="$name"></TD>\n<TD>\n$name</TD><TD>$privelages</TD></TR>\n|;
>       }
>
>     },
>
> });
>
>
> Benchmark: timing 100000 iterations of Orig1, Orig2, Ron, Ron2...
>      Orig1:  6 wallclock secs ( 5.72 usr +  0.00 sys =  5.72 CPU)
>      Orig2:  6 wallclock secs ( 5.48 usr +  0.00 sys =  5.48 CPU)
>        Ron:  5 wallclock secs ( 4.73 usr +  0.00 sys =  4.73 CPU)
>       Ron2:  5 wallclock secs ( 4.94 usr +  0.00 sys =  4.94 CPU)
>
> _______________________________________________
> Perl-Win32-Web mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to