Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: RFC CGI.pm refactoring

by Dog and Pony (Priest)
on Feb 14, 2002 at 18:06 UTC ( #145519=note: print w/ replies, xml ) Need Help??


in reply to RFC CGI.pm refactoring

Interesting. If nothing else, because I was pondering whether to do this exact same thing, and even more interesting, I was also gonna use the name CGI::Simple. :)

I use CGI.pm all the time, but I only use a very minor portion of the module, more specifically it is usually the header method, parameter parsing and redirects. Sometimes, some other minor stuff too, but that is about it. So why should I pull in the whole of CGI.pm, especially when web programming should be as fast as possible? Yes, I know about mod_perl and all that, but sometimes that is not possible, and sometimes it is not worth the effort - doesn't mean you shouldn't optimize when you can.

Do upload it. I for one will use it. Thanks for the effort. I appreciate it. :)


Comment on Re: RFC CGI.pm refactoring
Re: Re: RFC CGI.pm refactoring
by mirod (Canon) on Feb 14, 2002 at 18:38 UTC
    I use CGI.pm all the time, but I only use a very minor portion of the module (...) So why should I pull in the whole of CGI.pm, especially when web programming should be as fast as possible?

    I use Perl all the time but I only use a very minor portion of the language... you get the idea ;--)

    Basically the extra functionality comes for free. Have you looked at the code of CGI.pm? Unless you use a method it is never loaded. It uses tons of clever tricks, its own version of Exporter (saving you 300 lines), and under 700 lines of "real" code, the rest being loaded on demand.

    Are there any benchmarks of CGI::Simple against CGI?

      Yes there are. The test suite contains just under 1000 unit tests. This includes the entire CGI.pm CGI related test suite plus just under 100 concordance tests that have the basic form:

      use CGI; use CGI::Simple; use Test; # make a CGI environment; $ENV{'BLAH'} = .... [snip] my $qc = new CGI; my $qs = new CGI::Simple; my @params = qw(blah blah); my $qc_scalar = $qc->some_method(@params); my $qs_scalar = $qs->some_method(@params);; my @qc_array = $qc->some_method(@params);; my @qs_array = $qs->some_method(@params);; ok( $qs_scalar, $qc_scalar ); ok( join'',@qs_array, join'',@qc_array ) # continues for all common methods

      Concordance with CGI.pm 2.78 is 100%. CGI::Simple loads under 300 lines by default and uses Selfloader. As it is inherently OO it does not use Exporter at all and is considerably faster than CGI.pm when called OO. The wrapper module that gives you a functional interface CGI::Standard uses a couple dozen lines of code to make the namspace exports either on demand (using an AUTOLOAD routine) or as single methods or method sets.

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      As requested by /msg from mirod on Benchmarking CGI::Simple is just under 3 times faster performing the most common function - getting the value of a param. It is variably faster on other common operations. Load times are more difficult to evaluate accurately. I would be interested in what you find.

      use Benchmark; use CGI; use CGI::Simple; $ENV{'QUERY_STRING'} = 'foo=bar&baz=boo'; $q = new CGI; $s = new CGI::Simple; timethese(250000, {'CGI' =>'$q->param("baz")', 'Simple' => '$s->param( +"baz")'}); __DATA__ Benchmark: timing 250000 iterations of CGI, Simple... CGI: 27 wallclock secs (27.19 usr + 0.00 sys = 27.19 CPU) @ 91 +94.56/s (n=250000) Simple: 10 wallclock secs ( 9.99 usr + 0.00 sys = 9.99 CPU) @ 25 +025.03/s (n=250000)

      Update

      For a more in depth analysis see CGI::Simple vs CGI.pm - Is twice as fast good enough?

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Would you please benchmark this again?
        use Benchmark; use CGI qw/:cgi /; use CGI::Simple; $ENV{'QUERY_STRING'} = 'foo=bar&baz=boo'; $q = new CGI; $s = new CGI::Simple; timethese(250000, {'CGI' =>'$q->param("baz")', 'Simple' => '$s->param( +"baz")'});
        Sorry, but comparing fully blown CGI while forcing it to load all is quitely unfair in this case while CGI.pm has an option to run in a different manner.

        Have a nice day
        All decision is left to your taste

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://145519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-08-29 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (288 votes), past polls