SPUG: Is there some other recommended replacement for CGI.pm with Apache2?

Adam Monsen adamm at wazamatta.com
Thu Sep 18 18:26:56 CDT 2003


Cantrall, Christopher W wrote:
> I have repeatedely heard that CGI.pm only compiles what is needed,
> leaving the rest of the monster outside the castle gates, unable to
> slow down the festivities inside the Castle Script.  See the linked
> docs and discussions for more info, but suffice it to say that all of
> CGI.pm is not loaded every time your script starts.
> 
> I don't know if this is what Adam meant by "resource waster", or what
> Jerome meant by "isn't nearly the monster that it's reputed to be",
> but it's a complaint that I've heard many times, namely, loading
> 'that huge beast into my simple form script will slow the whole
> server'.  Adam, if I've missed your point, I'm sorry and could you
> clarify. :)

I basically said that CGI.pm is overkill for param extraction, and 
headers could be printed out by hand or with help from HTTP::Headers. 
Here's a benchmark comparing param setting and extraction with both 
CGI.pm and CGI::Minimal, showing CGI::Minimal to be approximately 3x 
faster. I'd definitely like to see other more complete and conclusive 
benchmarks.


#!/usr/bin/perl -w
use strict;
use Benchmark ();
use CGI ();
use CGI::Minimal ();

$ENV{REQUEST_METHOD} = 'GET'; # turn off STDIN processing

sub cgi_pm_test () {
   my $cgi = CGI->new;
   $cgi->param('name' => 'Joe Shmoe');
   my (@fake_input) = $cgi->param;
}

sub cgi_minimal_test () {
   my $cgi = CGI::Minimal->new;
   $cgi->param('name' => 'Joe Shmoe');
   my (@fake_input) = $cgi->param;
}

Benchmark::cmpthese 10_000,
{
   'CGI.pm'       => \&cgi_pm_test,
   'CGI::Minimal' => \&cgi_minimal_test,
}

# Typical result:
#
# $ perl -w cgitest.pl
#                Rate       CGI.pm CGI::Minimal
# CGI.pm       1089/s           --         -76%
# CGI::Minimal 4630/s         325%           --
#

__END__



-- 
Adam Monsen




More information about the spug-list mailing list