You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Stas Bekman <sb...@stason.org> on 2000/04/15 16:48:26 UTC

[correction] Benchmarking CGI.pm and Apache::Request

Well, Gunther has pointed out that the benchmark has been unfair, since
CGI.pm's methods have not been precompiled. I've also preloaded both
scripts this time to improve numbers and unloaded a system a bit while
running the tests. Here is the corrected version:

=head1 Benchmarking CGI.pm and Apache::Request

Let's write two registry scripts that use C<CGI.pm> and
C<Apache::Request> to process the form's input and print it out.

  benchmarks/cgi_pm.pl
  --------------------
  use strict;
  use CGI;
  my $q = new CGI;
  print $q->header('text/plain');
  print join "\n", map {"$_ => ".$q->param($_) } $q->param;

  benchmarks/apache_request.pl
  ----------------------------
  use strict;
  use Apache::Request ();
  my $r = Apache->request;
  my $q = Apache::Request->new($r);
  $r->send_http_header('text/plain');
  print join "\n", map {"$_ => ".$q->param($_) } $q->param;

We preload both modules that we ought to benchmark in the
I<startup.pl>:

  use Apache::Request ();
  use CGI  qw(-compile :all);

We will preload the both scripts as well:

  use Apache::RegistryLoader ();
  Apache::RegistryLoader->new->handler(
              "/perl/benchmarks/cgi_pm.pl",
   "/home/httpd/perl/benchmarks/cgi_pm.pl");
  Apache::RegistryLoader->new->handler(
              "/perl/benchmarks/apache_request.pl",
   "/home/httpd/perl/benchmarks/apache_request.pl");

Now let's benchmark the two:

  % ab -n 1000 -c 10 \

'http://localhost/perl/benchmarks/cgi_pm.pl?a=b&c=+k+d+d+f&d=asf&as=+1+2+3+4'
  
  Time taken for tests:   23.950 seconds
  Requests per second:    41.75
  Connnection Times (ms)
                min   avg   max
  Connect:        0     0    45
  Processing:   204   238   274
  Total:        204   238   319

  % ab -n 1000 -c 10 \

'http://localhost/perl/benchmarks/apache_request.pl?a=b&c=+k+d+d+f&d=asf&as=+1+2+3+4'
  
  Time taken for tests:   18.406 seconds
  Requests per second:    54.33
  Connnection Times (ms)
                min   avg   max
  Connect:        0     0    32
  Processing:   156   183   202
  Total:        156   183   234

Apparently the latter script using C<Apache::Request> is about 23%
faster. If the input is going to be larger the speed up in per cents
grows as well.

Again this benchmark shows that the real timing of the input
processing, when the script is much heavier the overhead of using
C<CGI.pm> can be insignificant.

______________________________________________________________________
Stas Bekman             | JAm_pH    --    Just Another mod_perl Hacker
http://stason.org/      | mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org  | http://perl.org    http://stason.org/TULARC/
http://singlesheaven.com| http://perlmonth.com http://sourcegarden.org
----------------------------------------------------------------------