This time we will focus on the startup time. The process start time is important if your processes are not persistent. If you are using FastCGI, mod_perl, mod_php, or mod_python, then these statistics are not so important to you. However, if you are spawning many processes which do something small and live for a very short time, then you should consider the CPU resources which get wasted while the script interpreter is being initialized.
The benchmarked scripts do only one thing – say “Hello, world” on the standard output. They do not include any additional modules in their source code – this may, or may not be your use-case. Though, very often the scripting languages have pretty many built-in functions, and for simple tasks you never need to include other modules.
Here are the benchmark results:
Language | CPU time | Slower than | |||
---|---|---|---|---|---|
User | System | Total | C++ | previous | |
C++ (with or w/o optimization) | 2.568 | 3.536 | 6.051 | – | – |
Perl | 12.561 | 6.096 | 18.723 | 209% | 209% |
PHP (w/o php.ini) | 20.473 | 13.877 | 34.918 | 477% | 86% |
Python | 27.014 | 11.881 | 39.318 | 550% | 13% |
Python + Psyco | 32.986 | 14.845 | 48.132 | 695% | 22% |
The clear winner among the script languages this time is… Perl. ๐
All scripts were invoked 3000 times using the following Bash loop:
time ( i=3000 ; while [ “$i” -gt 0 ]; do $CMD >/dev/null ; i=$(($i-1)); done )
All tests were done on a Kubuntu Lucid box. The versions of the used software packages follow:
- g++ (GNU project C and C++ compiler) 4.4.3
- Python 2.6.5
- Python Psyco 1.6 (1ubuntu2)
- Perl 5.10.1
- PHP 5.3.2 (1ubuntu4.2 with Suhosin-Patch), Zend Engine 2.3.0
The C++ implementation follows, click “show source” below to see the full source:
#include <iostream> using namespace std; int main() { cout << "Hello, world!\n"; return 0; }
The Perl implementation follows, click “show source” below to see the full source:
use strict; use warnings; print "Hello, world!\n";
The PHP implementation follows, click “show source” below to see the full source:
<?php echo "Hello, world!\n";
The Python implementation follows, click “show source” below to see the full source:
#import psyco #psyco.full() print 'Hello, world!'
Update (Jan/14/2012): Copied the used test environment info here.