Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI Question - Speed of compiled C vs Alternatives. 2

Status
Not open for further replies.

emmaUK

Programmer
Jan 23, 2006
10
GB
Hello all this is a general CGI question.

Can anybody tell me what the performance increase would be using compiled C CGI's over an interpreted language in real terms. There seems to be so few resources on the net for C/C++ CGI programming info I can't decide.

I'm interested as I have done a little win32 C/C++ and am new to any form of server side web development.
 
If you've done C/C++ then I'd suggest Perl or PHP, as their syntax is quite similar and would be easy to pick up. As you've said, C resources for CGI are scarce, your options will be greater if you can jump into a rich environment instead. Besides, the newer, higher-level scripting langages are faster and easier to write code in, and there are Apache modules that take away most of any speed advantage that C might have.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
If you are using a plain vanilla CGI approach, then the C will be faster than the Perl. Obviously, the Perl must be compiled every single run. However, if you are using apache with mod_perl, then apache will build the perl and keep a pre-built copy in memory ready for cloning to service any subsequent requests. This makes all but the very first Perl run, roughly similar to the speed you'd get with C, maybe even a little faster since mod_perl keeps a copy in memory and the C will have to be read from disk for each request.



'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks Guys!

I now know to move on from C CGI programming and into Perl/PHP the question is if I am going to invest time learning one of them for an(hopefully) high traffic site which one has the:

1: The better performance.
2: Best(overall) security.

Regards

dumbeast
 
It's a wash, you can find people and benchmarks that'll tell you either way, but I'm not sure I believe any of them. Always be wary of the benchmark between mod_php and perl_cgi, as such is very apples/oranges.

My personal preference is Perl, but you have to look and make such a decision yourself. Code is only as good as those that write it, so any generalizations like "perl thrives on obfuscation" or "php mixes up logic and layout too much" are only references to their programmers, not their languages.

Look at both, whatever you feel more comfortable writing code in and think will result in easily maintainable code is what you should go with. Also look at both support communities, check out their respective code libraries and documentation.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
@icrf, poetry, * 4 that

when a language becomes a function of one's view over another's, it's plain to see the 'PROCRASTINATOR' has been afoot

suck it and see, would be my advice ... trial, trial, and trial again ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
hehe, thanks.

If you're looking for the one sentence answer, my bias opinion (after a moderate amount of Perl work and minimal PHP) is that Perl has a higher learning curve, but greater rewards once you're there. PHP is stupid easy to get started writing code in, which IMHO is why it's so popular.

Whichever language you pick, find a good framework for your applications and try to get used to it quick. Perl has CGI::Application which I'm rather fond it. It makes a good structure for the application as a whole, and offers easy access to CGI, CGI::Session, HTML::Template, etc. I think Amazon.com uses Mason, but I haven't. PHP has various templating libraries, too. Only one I can remember off the top of my head is Smarty.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
To answer your original question, compiled CGI applications can offer sigificantly better performance over intepreted CGI scripts. It can be 10:1 or better.

The real fact of the matter though is unless your CGI logic is really compute-intensive you'll probably never notice the difference. In most cases the CGI API itself is the bottleneck. True CGI involves starting extra processes and communicating through some clunky interfaces, where alternatives can reuse threads and streamline the communication process generally.

There are so many variables involved that comparisons are very difficult except between almost-identical cases.

The main use of compiled CGI today is probably for creating "drop in, shrink wrapped" web applications. Compiled CGI code is more difficult to plagiarize or reverse engineer and can be used with several web server products (on a given platform at least, usually Windows). Most compiled CGI doesn't require extra support software (such as script interpreters) or touchy server configuration. License key management is also something more securely accomplished in compiled code. To a limited extent compiled CGIs are more secure than using interpreted script too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top