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

Re: Re: Re: Re: RFC refactoring

by little (Curate)
on Feb 15, 2002 at 15:12 UTC ( #145690=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: RFC refactoring
in thread RFC refactoring

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: RFC refactoring
by Masem (Monsignor) on Feb 15, 2002 at 15:18 UTC
    And even then, with this test, while it's fair in how fast it accesses, the real concern would be the speed in breaking down the query string. I propose a better test would be :
    use Benchmark; use CGI qw/:cgi /; use CGI::Simple; $ENV{'QUERY_STRING'} = 'foo=bar&baz=boo'; timethese(250000, {'CGI' => '$q = new CGI; $q->param("baz")', 'Simple' => '$s = new CGI::Simple; $s->param( +"baz")'});

    Dr. Michael K. Neylon - || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

      The qw/:cgi/ part is wrong as noted above but as you note there are a number of factors to CGI speed. Have a look at CGI::Simple vs - Is twice as fast good enough? for a much more thorough analysis.




Re: Re: Re: Re: Re: RFC refactoring
by tachyon (Chancellor) on Feb 15, 2002 at 15:48 UTC

    Actually you completely fail to understand how works. When you use CGI; you import 0 methods. The methods are available via the OO interface and compiled on demand. When you use CGI qw/:cgi/; you import and compile the basic cgi methods (which you would otherwise not do with a straight use CGI;). As we are making OO calls this is a complete waste of time. Running your example you can see that the time remains essentially the same as expected (loading the extra methods once (with the use CGI qw/:cgi/;) adds about a second to the load time but this is a once off price and we are then looping.

    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")'}); __DATA__ Benchmark: timing 250000 iterations of CGI, Simple... CGI: 29 wallclock secs (27.53 usr + 0.00 sys = 27.53 CPU) @ 90 +81.00/s (n=250000) Simple: 10 wallclock secs ( 9.99 usr + 0.00 sys = 9.99 CPU) @ + 25025.03/s (n=250000)




Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2016-10-27 01:44 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (351 votes). Check out past polls.