Monday, September 1, 2008

Benchmarking die("Hello world!"); VS. exit("Hello world!"); VS. echo "Hello World!"; on PHP

After doing some useful and problem solving benchmarking with Siege we can scream to every corner of the world that exit() is faster than die() and echo

Show me the facts! I hear you screaming. Let there be facts!:

echo "Hello world!";
Transactions:         250 hits
Availability:      100.00 %
Elapsed time:        7.10 secs
Data transferred:        0.00 MB
Response time:        0.01 secs
Transaction rate:       35.21 trans/sec
Throughput:        0.00 MB/sec
Concurrency:        0.20
Successful transactions:         250
Failed transactions:           0
Longest transaction:        0.05
Shortest transaction:        0.00


die "Hello world!";
Transactions:         250 hits
Availability:      100.00 %
Elapsed time:       10.04 secs
Data transferred:        0.00 MB
Response time:        0.01 secs
Transaction rate:       24.90 trans/sec
Throughput:        0.00 MB/sec
Concurrency:        0.17
Successful transactions:         250
Failed transactions:           0
Longest transaction:        0.04
Shortest transaction:        0.00


exit "Hello world!";
Transactions:         250 hits
Availability:      100.00 %
Elapsed time:        6.05 secs
Data transferred:        0.00 MB
Response time:        0.01 secs
Transaction rate:       41.32 trans/sec
Throughput:        0.00 MB/sec
Concurrency:        0.27
Successful transactions:         250
Failed transactions:           0
Longest transaction:        0.04
Shortest transaction:        0.00


The previous test were performed simulating 25 concurrent users with a 10 times repetition. Now just imagine for one minute (or two if you need more) if 20.000 concurrent users hits your echo "Hello World" website! That will be a mess! Just by imagine myself this scenario I can't stop hearing the sirens on my mind, so please, grep through your code and preg_replace() all those echo "Hello world!" you may have there! 


4 comments:

Unknown said...

Whaaaaaat??? which kind of test is this???? 75 hits for exit and 250 hits for the others... Obviously wrong!

Alvaro Videla said...

@boby
Nice point! Fixed!

Unknown said...

tsss, you covered up your failure; but I know and people will too. Still it misses some details of your experimentation like the php source code used, the compilation flags for php... Overall and being very tolerant, it looks like exit is the way to go. Can we see an concrete example on how to use this? An integration in a small MVC design pattern?

Amephist said...

PHP source code for 5.3.7
File: ./Zend/zend_language_scanner.l
Line: 873-879

"exit" {
return T_EXIT;
}

"die" {
return T_EXIT;
}

Should be the same result for die and exit, we recommend verify the results on the test.

Best Regards