2 Replies - 600 Views - Last Post: 05 December 2009 - 11:50 PM

#1 ethereal1m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 214
  • Joined: 30-June 09

what is the best method to create an engine in terms of performance

Post icon  Posted 03 December 2009 - 11:33 PM

Hi all,
Suppose in my website I have an engine that does a particular functionality, let's say arithmetic calculation. In terms of performance, what is the best way to implement this?

I always thought attaching an executable (compiled from c or c++ for example) in the website works the best in terms of performance and scalability compare to implementing scripts like javascript, php, or ajax. But this is only my assumption since I have shallow knowledge on website development.

So my question is, what is the best way to implement a function in a website in terms of performance, scalability, and security? What are their drawbacks and advantages?

much appreciated :)

Is This A Good Question/Topic? 0
  • +

Replies To: what is the best method to create an engine in terms of performance

#2 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: what is the best method to create an engine in terms of performance

Posted 05 December 2009 - 06:18 AM

Yes, a C program will, in general, run faster than a PHP program. However:

1) A C program will generally take a good deal longer to write than an equivalent PHP program, unless you're a C expert, but just learning PHP.

2) Programmer time is expensive. Processor time is cheap. Even if you're a horribly underpaid programmer, making a mere $10/hr, your employer is probably paying $25/hr to have you around after taking in the cost of benefits, floorspace for your cube, etc. That's $1000/week. No matter how much faster the C version may run than the PHP version, you still come out ahead by taking the $1000/week saved by PHP's quicker development time and using it to buy more servers.

3) Unless you're doing some seriously heavy-duty processing to handle each request, if you run it through CGI, the per-request startup time will dwarf your code's execution time. The most important thing by far in getting web apps to run quickly is to get them running as a persistent process (integrated into the web server as an apache module, run them under FastCGI, etc.) instead of through CGI. Being CGI doesn't hit C as hard as it hits PHP/Perl/Python/Ruby because C is compiled in advance, while the others have to be compiled each time they run, but even C still has the overhead of spawning a new process for each request when run via CGI.

4) The next biggest contributor to the amount of time needed to bring up a page is network latency. If it takes the user's browser 2 seconds to connect to the web server, download the page, and render it, then it doesn't really matter whether it takes the server 0.2 seconds or 0.002 seconds to generate the page, does it?

So don't worry about performance unless and until it becomes an actual issue. Choose the language that allows you to work the most effectively and be the most productive. If and when an actual performance issue arises, you can profile the code to find out where it's spending the most time and then do targeted conversions of those sections to C - unless it would be more cost-effective to just buy a newer and/or bigger server instead of eating the development cost.

As for the other factors:
  • Javascript and AJAX are largely orthogonal to all the issues you raised. JS runs in the user's browser and is the only thing that will run there without requiring the user to install a plugin. If you have user-side processing to do, you use JS and if you don't, you don't. JS and server-side languages are not particularly fungible.

    AJAX is a communication method for allowing user-side JS and server-side code (in any language) to interact. Once again, it's pretty much the only game in town for what it does. Some folks do factor it in as a contributor to performance, in that it lets you send the page piecemeal, update only selected sections, and other such tricks that can make things feel faster/more responsive, but I see that more as a design technique rather than a technology issue. Plus, loading up a page as a series of 5 AJAX requests will ultimately be slower than loading it up as a single full-page load (5 round trips to the server will take longer than 1 will), even if it feels faster to the user.


  • Scalability is largely language-independent and will be determined primarily by your design, the libraries you use, and how you use them.


  • Security is where C really falls down for web development, IMO. While you absolutely can create a secure site with C, it's much more difficult than in memory-managed languages. Having to manage memory yourself opens up entire classes of security issues (buffer overflow, anyone?) that just don't exist in memory-managed languages. You still have to be careful and security-conscious regardless of the language, of course, but why make yourself worry about memory issues if you don't have to?

Was This Post Helpful? 1
  • +
  • -

#3 ethereal1m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 214
  • Joined: 30-June 09

Re: what is the best method to create an engine in terms of performance

Posted 05 December 2009 - 11:50 PM

@dsherohman,
to me this is a very valuable information! thanks a bunch :^: :D !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1