|go ahead... be a heretic|
CGI::Simple vs CGI.pm - Is twice as fast good enough?by tachyon (Chancellor)
|on Feb 16, 2002 at 00:06 UTC||Need Help??|
After posting RFC CGI.pm refactoring a number of monks raised a very valid point - "Why bother?". CGI.pm is stable and its use widespread. Why bother changing from this? One 'good' reason might be speed. As a number of monks have requested speed comparison benchmarks with CGI.pm here are a range of them. Executive summary CGI::Simple is about twice as fast as CGI.pm depending on what you are talking about.
To use a module you need to load it, make an object, then extract stuff from that object. Depending on whether you are using mod perl or not you may or may not need a new process. Here are some tests:
To do the load test we need to trick perl into reloading the modules over and over which we do by by undefing %INC and requiring them in:
As you can see CGI::Simple will load about 38% faster in standard form. To compare apples with apples I commented out the use strict; in CGI::Simple to remove the overhead of loading strict.pm which makes CGI::Simple load 79% faster than CGI.pm. While use strict; is excellent (and highly recommended) for development it does carry a penalty at compile time.
Extracting data from a CGI object
Now lets have a look at how fast we can extract data from our CGI object:
As you can see CGI::Simple is 43% faster making a new object and getting one param or 68% faster making a new object and getting 10 params.
Module loading and data extraction
In practical terms the module load time is often a choke point (depending on the application). Here is a test that tests module loading, object creation and parameter parsing together (note we don't completely undef %INC this time as we need to keep Benchmark.pm in %INC):
Unless you are using mod perl this testing is still inadequate as the startup time for a new process is not measured. This forms a significant part of serving a CGI request. Nonetheless there is a raw 134% performance improvement for using CGI::Simple over CGI.
New process creation testing
So, finally here is some data on the whole shebang: new process, load the module, make a new object and get some param data out:
So testing the whole shebang CGI::Simple is just over 80% faster performing the same task.
However you want to look at this data it equates to being able to handle a lot more requests on the same server. To change from CGI to CGI::Simple is a one line change as the interface is identical.... Is it worthwhile considering? For me yes, for you who knows?