February 10, 2010

Python and php benchmark


Hi!
It's been a long time since the last time I wrote a post.

I'm installing a web environment and I'm trying to make it as efficient as possible,
so I've decided to make a benchmark between Php and python
I've tried these two web environments:

Php: default configuration (php5 + Apache)
Python: Cherokee webserver+fcgi+Psyco

Cherokee is a minimalist web server like nginx. I decided to use this web server since I've read
that it is more efficient than apache, according to several benchmarks.

Psyco is a JIT Compiler for python that compiles chunks of code to make it faster when executing.

The benchmark consists of a fuzz of 1000 requests using 50 parallel threads.

This was the result (Y axis:System Load , X axis:Time)



I know that php can be optimized, but this was a simple benchmark that I made to test
my new environment, however it evaluates default php installations.

I hope you begin to port to Python ;D

Let's see how HipHop works

Bye!

Pd: That was the script I used

  1. def func():
  2. primeNumbers = []
  3. output = []
  4. for i in xrange(2, 30000):
  5. divisible = False
  6. for number in primeNumbers:
  7. if i % number == 0:
  8. divisible = True
  9. if divisible == False:
  10. primeNumbers.append(i)
  11. output.append(str(i))
  12. print "".join(output)
  13. func()
  1. $primeNumbers = array();
  2. $output = '';
  3. for ($i = 2; $i 30000; $i++) {
  4. $divisible = false;
  5. foreach ($primeNumbers as $number) {
  6. if ($i % $number == 0) {
  7. $divisible = true;
  8. }
  9. }
  10. if ($divisible == false) {
  11. $primeNumbers[] = $i;
  12. $output .= $i;
  13. }
  14. }
  15. echo $output;