Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: RFC 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 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 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, 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. :)

Replies are listed 'Best First'.
Re: Re: RFC refactoring
by mirod (Canon) on Feb 14, 2002 at 18:38 UTC
    I use all the time, but I only use a very minor portion of the module (...) So why should I pull in the whole of, 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 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 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 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 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.



      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)


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




        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 has an option to run in a different manner.

        Have a nice day
        All decision is left to your taste

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-10-25 07:06 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.