in reply to Re^4: Should I just print my own HTTP headers?
in thread Should I just print my own HTTP headers?

It's actually even worse. You're actually loading CGI only once. If you'd reload CGI every time in the loop, you'd get far worse figures.

You could do that by deleting 'CGI.pm' from %INC. You'd then probably get a lot of warnings on redefined subs, so you should rather do something like

delete $INC{'CGI.pm'}; no warnings 'redefine'; # or 'redefined'? Gah, I hate that! require CGI; my $cgi = CGI->new; print OUT $cgi->header;

Also, CGI->new parses the form parameters, you should take that into account. It's something you probably want to do anyway.

Replies are listed 'Best First'.
Re^6: Should I just print my own HTTP headers?
by Cap'n Steve (Friar) on Apr 06, 2007 at 21:20 UTC
    Thanks for the tips. Forcing it to search for CGI.pm every time only makes the print statement 12471% more efficient, but when not using the object-oriented interface, the print statement is 3551% more efficient.

      If you had a million hits in one day... 1,000,000 / 24 =~ 41,666 per hour / 60 =~ 694 per minute = 11.5 per second. In my machine both of the options perform at over 6000 operations per second. In order for CGI to become my bottleneck then i would need 518,400,000 hits per day!!!! Yes this assumes a uniform distribution, but the numbers...look at them!! And this is on a PC not a web server and a single one, not a load balanced situation that you should have if you are approaching these kinds of hits. Is yours faster? Yes certainly, but CGI is a well worn tool, it will do what you need now, and down the road it will step up and do things you didn't even know you needed, not bite you in the arse like a hand built solution may.

      Use what you want but don't make statments like 12471% more efficient like that is a reason to squeeze this particular piece of code.


      ___________
      Eric Hodges
        Your example is true if all you're doing is printing headers, and if you're on a dedicated server, and if you're not running a database server. The way I'm arranging this site, there will be one script that will probably be run at least 100 times more than any other. I'd rather be cautious and not get kicked off my host for using too many resources.

        Since know one seems to know of any situation where hand-crafted headers might be a problem, I'll just do that and I can switch to CGI later if I need to. The more complicated and less popular scripts can still use CGI.