I couldn't find the original scripts (it was a good while ago and the point was proven then) so I've knocked up these scripts today which follow the same principle. If you can point out the errors in what I've done that would be most helpful.

Firstly, here's the trivial non-plack CGI:

#!/usr/bin/perl use strict; use warnings; use CGI::Lite; my $cgi = CGI::Lite->new; $cgi->parse_form_data; print "Content-Type: text/plain\n\n"; $cgi->print_data; exit;

Here's the equivalent PSGI:

use strict; use warnings; use Plack::Request; my $app = sub { my $env = shift; my $req = Plack::Request->new($env); my %params = %{$req->parameters}; my $body = ''; while (my ($k, $v) = each %params) { $body .= "$k = $v\n"; } my $res = $req->new_response; $res->status (200); $res->headers ({ 'Content-Type' => 'text/plain' }); $res->body ($body); $res->finalize; }

And finally the wrapper to turn the PSGI into a CGI:

#!/usr/bin/perl use strict; use warnings; use Plack::Loader; my $app = Plack::Util::load_psgi("light.psgi"); Plack::Loader->auto->run($app);

To turn this into a "real" test I've run these through Apache with both client and server on the same host (ie. no network issues). The 2 cgi scripts were called with a single key-value pair in the query string (foo=bar, since you ask) and produced the same content as a result. Each script was called 11 times (1 as PoC and then another 10)

The timings come from the apache log (with %D) and are as follows (all values are microseconds).

Normal CGICGI through Plack
Maximum2137193761
Minimum1249480521
Mean1499986481

So, looking at the mean request time the plack version is 5.77 times slower than the plain CGI.

Now, these are small samples and are wallclock times so YMMV and I encourage you to re-run the tests on your own platforms to see how they compare but this crude example reflects pretty closely what I originally saw and is enough of a penalty to be avoided (for me).


In reply to Re^10: appending to html at beginning (don't use CGI.pm) by hippo
in thread appending to html at beginning by Limbomusic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.