CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?) 
Author Message
 CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?)

[ Followups set to comp.lang.perl.modules ]

Quote:



> > Thanks, Sir. I wonder if you could give me a more specific example or reason
> > why CGI.pm is better than cgi-lib.pl. That is, I don't seme to be fully
> > convinced yet.

> What is unconvincing about CGI.pm being more reliable, less buggy,
> still supported, part of the standard distribution, having better
> debugging capabilities, being more flexible? What is unconvincing of
> CGI.pm even having a cgi-lib 'compatibility' mode which allows you to
> still use your old code? I don't get it. Did you read any of responses
> you got?

All these things are true about CGI.pm, but I just ran a quick
benchmark, and CGI.pm is quite a bit slower than cgi-lib.pl (results
discussed below).  If speed and web server load are issues, and if all
that's needed is basic functionality, then cgi-lib.pl might be a more
desirable alternative.

What I did was to post identical <FORM> data to a simple CGI script
that loaded either CGI.pm or cgi-lib.pl, depending on the contents of
the PATH_INFO enviroment variable (which is set via the URL in the
`action' clause of each of the <FORM> tags -- see below).  The script
then retrieved the variable values from the form and listed them on
the returned web page.

I used Time::HiRes to capture the total elapsed time of the script
(until HTML printing) and also to calculate the elapsed time after
the initial load of the module (CGI.pm or cgi-lib.pl) had taken place.
In both cases, CGI.pm was quite a bit slower.

This is by no means an exhaustive benchmark.  I'm sure that those of
you who might be interested in pursuing this further could come up
with many more comparison scenarios.  However, this benchmark does
illustrate the relative efficiencies of the two modules.

All my benchmark code is attached at the bottom of this post.  But
first, here are the benchmark results (averages are computed over 10
iterations):

                Avg. total elapsed time       Avg. elapsed time
Module          including load time           after initial load
----------      -----------------------       ------------------
cgi-lib.pl          0.0189837 sec                0.0019999 sec
CGI.pm              0.1935548 sec                0.0752660 sec

As you can see, CGI.pm is much slower than cgi-lib.pl for the simple
processing perfomed in this test.

These results were computed using a Pentium Pro 200 MHz box running
RedHat Linux 5.0 and Perl 5.004_04.  The web server is Apache 1.3b6.

Here's the main CGI benchmark script (named `test' in my CGI directory):
------------------------------------------------------------------------
#!/usr/bin/perl
# -*- perl -*-

use Time::HiRes;

$startTime = [Time::HiRes::gettimeofday];

%results = ();

($program = $0) =~ s:.*/::;

($pathInfo = $ENV{'PATH_INFO'}) =~ s:^/::;

# Load the variable values into the %results hash in both cases, for
# the purpose of uniformity.

if ($pathInfo eq "CGI") {
   require "./test-CGI.pl";      # (see below)
   $loadedTime = [Time::HiRes::gettimeofday];
   $q = new CGI;

     $results{$item} = $q->param($item);
   }

Quote:
}

else {
   require "./test-cgi-lib.pl";  # (see below)
   $loadedTime = [Time::HiRes::gettimeofday];
   ReadParse();

     $results{$item} = $in{$item};
   }

Quote:
}

print <<EOD;
Content-type: text/html

<html>

<head>
<title>Test of CGI vs. cgi-lib</title>
</head>

<body>

<b>Test of $pathInfo</b><br><br>

<table>
EOD

foreach $item (sort keys %results) {
   print <<EOD;
 <tr>
  <td align="left"><b>Key: $item</b></td>
  <td align="left"><b>Value: $item</b></td>
 </tr>
EOD

Quote:
}

print <<EOD;

</table>

<br>

EOD

$totalElapsed = Time::HiRes::tv_interval($startTime);
$sinceLoading = Time::HiRes::tv_interval($loadedTime);

print <<EOD;
<b>Total elapsed time:
$totalElapsed seconds</b><br>
<b>Elapsed time since loading of <i>$pathInfo</i>:
$sinceLoading seconds</b><br>

</body>

</html>
EOD

exit(0);

__END__

Here are the contents of the `test-CGI.pl' include file:
--------------------------------------------------------
use CGI;
1;

Here are the contents of the `test-cgi-lib.pl' include file:
------------------------------------------------------------
require 'cgi-lib.pl';
1;

Here's the web page for invoking the main CGI benchmark script:
---------------------------------------------------------------
<html>

<head>
<title>Form Test</title>
</head>

<body>

<b>This is a timing test of <i>CGI.pm</i> versus <i>cgi-lib.pl</i>.<br><br>
For the most accurate results, please don't change any of the values in
the input fields.  Just click on one or the other of the submit buttons.</b>

<br><hr><br>

<form action="/cgi/test/cgi-lib" method="post">
<input name="aaa" value="aaa">
<input name="bbb" value="bbb">
<input name="ccc" value="ccc">
<input name="ddd" value="ddd">
<input name="eee" value="eee">
<input name="fff" value="fff">
<input name="ggg" value="ggg">
<input name="hhh" value="hhh">
<input type="submit" value="Test cgi-lib.pl">
</form>
<hr><br>
<form action="/cgi/test/CGI" method="post">
<input name="aaa" value="aaa">
<input name="bbb" value="bbb">
<input name="ccc" value="ccc">
<input name="ddd" value="ddd">
<input name="eee" value="eee">
<input name="fff" value="fff">
<input name="ggg" value="ggg">
<input name="hhh" value="hhh">
<input type="submit" value="Test CGI.pm">
</form>
<br>

</body>

</html>

--

 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;




Fri, 20 Oct 2000 03:00:00 GMT  
 CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?)



Quote:
> [ Followups set to comp.lang.perl.modules ]
> All these things are true about CGI.pm, but I just ran a quick
> benchmark, and CGI.pm is quite a bit slower than cgi-lib.pl (results
> discussed below).  If speed and web server load are issues, and if all
> that's needed is basic functionality, then cgi-lib.pl might be a more
> desirable alternative.

This is probably true for everything that wraps functionality and data
in classes, and does all the necessary error checks and stuff that
goes with that. Encapsulation comes at a price. If you don't want to
pay that price, then you should roll your own custom written stuff.
That is even faster than using cgi-lib.pl, and at least the bugs are
then more under your control. If server load is really a big issue,
then probably the overhead of perl itself is an expensive price to pay
(unless maybe you use mod_perl on Apache or something like that).
Writing your own stripped down custom executables in C or assembly
probably is the way to go then.

I am mainly trying to make the point that for every level of
abstraction, and for every piece of general code that you use, you do
pay a performance price (most of the time). This is even true for
cgi-lib.pl.

Martien
--
Martien Verbruggen                  |
Webmaster www.tradingpost.com.au    | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd.       | inexactitude.
NSW, Australia                      |



Sat, 21 Oct 2000 03:00:00 GMT  
 CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?)

: I am mainly trying to make the point that for every level of
: abstraction, and for every piece of general code that you use, you do
: pay a performance price (most of the time). This is even true for
: cgi-lib.pl.

        What we need is CGI.pm recoded using XS with well optimized C code.
        :-)

--
-Zenin



Sat, 21 Oct 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Whats better cgi-lib.pl or cgi.pm?

2. Whats better cgi-lib.pl or cgi.pm?

3. CGI.pm or CGI-LIB.pl

4. novice question re CGI.pm/cgi-lib.pl

5. cgi-lib.pl vs CGI.pm?

6. cgi-lib.pl or CGI.pm?

7. Problems with http file upload using cgi.pm and cgi-lib.pl

8. cgi-lib.pl vs CGI.pm

9. Whats better cgi-lib.pl or cgi.pm?

10. ns-upload, CGI.pm & cgi-lib.pl

11. cgi.pm .vs. cgi-lib.pl

12. Problems with Enterprise with cgi-lib.pl/fup.html/fup.cgi

 

 
Powered by phpBB® Forum Software