Peter Leonov's Blog

Simpliest CGI script

09 December 2008

Let's swith for a bit fron nginx internals. For fun not profit I want to compare how fast the modern script languages can run as CGI scripts. CGI is old, not hot, but very stable.

Here a static file, compiled C, Perl, Ruby, Python and JavaScript (SpiderMonkey) have been compared. Surely the performance would not depend on the language itself but from its platform: creating pipe, setting environment variables, fork, then each interpreter does it's job of setting up classes and global variables, etc, and only then it parses the file and produces the desired output. For C most of it is not relevant so I use it as a reference.

Here are rusults. For comparising a static file nginx serves 5201.02 times per second and JS built in nginx responses up to 15,000 times per second:

  • С: 600,07;
  • Perl: 419,53;
  • Ruby: 271,65;
  • Python: 32,45;
  • JavaScript: 403,00.

It's obvious that I do not know how to prepare Python right. In other cases everything shows that prefork would definitely be needed.

Tested on: Intel Core 2 Duo, 2.16 GHz, 4 Mb L2, 2 Gb memory. Mac OS X 10.5.5 (9F33), Darwin 9.5.0.


  • JavaScript-C 1.7.0 2007-10-03
  • ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
  • python 2.5.2
  • perl 5.8.8 (darwin-2level)
  • gcc version 4.0.1 (Apple Inc. build 5488)

  • backend
  • benchmark
  • C
  • cgi
  • javascript
  • perl
  • python
  • ruby
  • spidermonkey