Every so often I write a script to measure how long various common things in my current scripting language take. The difference between the versions is quite large.

Third party benchmarks

I haven't checked that the site testers download all the resources, i.e. pull a page, then download all the attached JS and CSS. This pipelining is a useful feature of HTTP1.1.

  1. http://www.phpbench.com/
  2. http://www.php-benchmark-script.com/
  3. https://github.com/fotuzlab/appgati
  4. http://www.metamorphosite.com/php-benchmarks-loops-arrays
  5. http://jmeter.apache.org/
    1. this is a good reputation, but its for Java
  6. http://www.cyberciti.biz/tips/howto-performance-benchmarks-a-web-server.html
    1. this is for Apache not php, but is usefull as a structure
  7. http://acme.com/software/http_load/
    1. again a site tester

My performance benchmark

This results are for PHP 5.4.17RC1 (cli) (built: Jun 22 2013 06:27:20) running on Linux iCeLine 3.2.0-45-generic-pae with Arch: i686, CPU(s): 2, CPU MHz: 2800.000 . At the end, there is a more recent set, on the same hardware.

This is for the version of PHP installed on my workstation at home. The computer isn't doing much when I ran this test. I ought to run this script for 5.1, 5.2, and 5.3 in addition. This script will get increasingly long as I add more categories of results. It is available under GPL, but you may want to use the version attached to the iceline project that includes the HTML renderer.

The test script creates loads of lambda functions, in PHP these are not managed by the data memory management.

  1. http://stackoverflow.com/questions/1735492/is-there-garbage-collection-in-php
  2. http://stackoverflow.com/questions/2461762/force-freeing-memory-in-php

Please see next build.

Test of:Duration (n=100000)deltaRAM
Stats for creating LD1 0.0037s0 MB
Stats for creating LD2 0.5027s100 MB
Stats for creating LD3 0.0120s800 KB
Stats for creating LD4 0.0074s500 KB
[0] linear increment (1php byte code)0.0079s0 B
[1] linear increment (1php byte code)0.0060s0 B
[2] linear float addition0.0075s0 B
[3] linear float increment0.0084s0 B
[4] linear float increment (+1)0.0071s0 B
[5] float increment (cast alot)0.0105s0 B
[6] linear float increment(cast)0.0090s0 B
[7] string creation0.0085s0 B
[8] string concat (inc RAM)0.0129s300 KB
[9] html entities ~ plain0.0539s0 B
[10] html entities ~ entities0.0668s0 B
[11] func int addition0.0291s0 B
[12] func float addition0.0296s0 B
[13] func string creation0.0254s0 B
[14] func string cat1.3472s300 KB
[15] reference string cat0.0263s0 B
[16] reference int increment0.0211s0 B
[17] EVAL linear float increment0.2614s300 KB
[18] EVAL linear int increment 0.2648s0 B
[19] EVAL linear float addition0.2875s0 B
[20] EVAL string creation0.3015s0 B
[21] EVAL string concat0.9640s800 KB
[22] for loop4.9206s0 B
[23] foreach ($v only) loop6.3449s0 B
[24] while list0.0319s0 B
[25] foreach ($k=>$v) loop8.7256s0 B
[26] simple array_key_exists0.0257s0 B
[27] isset0.0106s0 B
[28] in_array0.0281s0 B
[29] empty0.0086s0 B
[30] simple array_key_exists largeData13.0074s0 B
[31] isset largeData0.0083s0 B
[32] in_array largeData18.6237s0 B
[33] empty largeData0.0085s0 B
[34] largerData2 array_key_exists16,883.9806s0 B
[35] isset largeData20.0092s0 B
[36] largerData2 in_array18,176.7208s0 B
[37] empty largeData20.0094s0 B
[38] largerData3 array_key_exists164.1379s0 B
[39] empty largeData30.0102s0 B
[40] largerData3 isset0.0096s0 B
[41] largerData3 in_array211.8777s0 B
[42] largerData4 array_key_exists76.9961s0 B
[43] isset largeData40.0089s0 B
[44] largerData4 empty0.0087s0 B
[45] largerData4 in_array96.8175s0 B
[46] uniqid6.3382s0 B
[47] md50.0676s0 B
[48] sha10.1145s0 B
[49] sha2560.1481s0 B
[50] sha5120.4564s0 B
[51] tiger128,30.1192s0 B
[52] adler320.0662s0 B
[53] crc32b0.0667s0 B
[54] whirlpool0.3708s0 B
[55] haval224,30.2037s0 B
[56] strcmp by == match0.0099s0 B
[57] strcmp by == match 2vars0.0101s0 B
[58] strcmp by == nomatch0.0107s0 B
[59] strcmp by strcmp0.0321s0 B
[60] strcmp by !strcmp0.0302s0 B
[61] strcmp by strcmp 2vars0.0261s0 B
[62] strcmp by reg0.2876s0 B
[63] strcmp by strstr0.0412s0 B
[64] strcmp by preg_match 10.0890s0 B
[65] global obj method call0.0457s0 B
[66] local obj method call0.0320s0 B
[67] local obj method call0.0286s0 B
[68] via call_user_func_array0.1794s0 B

This second set of results was run on a smaller box, running php5.2.8 “oracle linux”

Test of:Duration (n=10000)deltaRAM
Stats for creating LD1 0.0051s0 MB
Stats for creating LD2 0.4412s100 MB
Stats for creating LD3 0.0089s0 MB
Stats for creating LD4 0.0057s800 KB
[0] linear increment (1php byte code)0.0008s0 B
[1] linear increment (1php byte code)0.0005s0 B
[2] linear float addition0.0005s0 B
[3] linear float increment0.0010s0 B
[4] linear float increment (+1)0.0006s0 B
[5] float increment (cast alot)0.0008s0 B
[6] linear float increment(cast)0.0010s0 B
[7] string creation0.0008s0 B
[8] string concat (inc RAM)0.0008s0 B
[9] html entities ~ plain0.0060s0 B
[10] html entities ~ entities0.0104s0 B
[11] func int addition0.0023s0 B
[12] func float addition0.0034s0 B
[13] func string creation0.0023s0 B
[14] func string cat0.0077s0 B
[15] reference string cat0.0022s0 B
[16] reference int increment0.0022s0 B
[17] EVAL linear float increment0.0143s300 KB
[18] EVAL linear int increment 0.0152s0 B
[19] EVAL linear float addition0.0161s0 B
[20] EVAL string creation0.0159s0 B
[21] EVAL string concat0.0184s300 KB
[22] for loop0.4287s0 B
[23] foreach ($v only) loop0.3885s0 B
[24] while list0.0035s0 B
[25] foreach ($k=>$v) loop0.5616s0 B
[26] simple array_key_exists0.0021s0 B
[27] isset0.0011s0 B
[28] in_array0.0021s0 B
[29] empty0.0007s0 B
[30] simple array_key_exists largeData1.0895s0 B
[31] isset largeData0.0008s0 B
[32] in_array largeData1.5965s0 B
[33] empty largeData0.0008s0 B
[34] largerData2 array_key_exists1,341.9421s0 B
[35] isset largeData20.0008s0 B
[36] largerData2 in_array1,369.9933s0 B
[37] empty largeData20.0008s0 B
[38] largerData3 array_key_exists8.5157s0 B
[39] empty largeData30.0008s0 B
[40] largerData3 isset0.0008s0 B
[41] largerData3 in_array10.7186s0 B
[42] largerData4 array_key_exists5.3160s0 B
[43] isset largeData40.0011s0 B
[44] largerData4 empty0.0010s0 B
[45] largerData4 in_array6.3577s0 B
[46] uniqid10.8791s0 B
[47] md50.0051s0 B
[48] sha10.0074s0 B
[49] sha2560.0109s0 B
[50] sha5120.0139s0 B
[51] tiger128,30.0066s0 B
[52] adler320.0052s0 B
[53] crc32b0.0060s0 B
[54] whirlpool0.0185s0 B
[55] haval224,30.0150s0 B
[56] strcmp by == match0.0012s0 B
[57] strcmp by == match 2vars0.0011s0 B
[58] strcmp by == nomatch0.0010s0 B
[59] strcmp by strcmp0.0028s0 B
[60] strcmp by !strcmp0.0025s0 B
[61] strcmp by strcmp 2vars0.0023s0 B
[62] strcmp by reg0.1418s0 B
[63] strcmp by strstr0.0038s0 B
[64] strcmp by preg_match 10.0168s0 B
[65] global obj method call0.0044s0 B
[66] local obj method call0.0039s0 B
[67] local obj method call0.0052s0 B
[68] via call_user_func_array %0.2531s0 B

The most useful results are for PHP 5.5.6-1, run on the same box as the first results.

Test of:Duration (n=10000)deltaRAM
Stats for creating LD1 0.0051s0 MB
Stats for creating LD2 1.5619s100 MB
Stats for creating LD3 0.0316s800 KB
Stats for creating LD4 0.0251s500 KB
[0] linear increment (1php byte code)0.0034s0 B
[1] linear increment (1php byte code)0.0029s0 B
[2] linear float addition0.0031s0 B
[3] linear float increment0.0032s0 B
[4] linear float increment (+1)0.0031s0 B
[5] float increment (cast alot)0.0033s0 B
[6] linear float increment(cast)0.0032s0 B
[7] string creation0.0031s0 B
[8] string concat (inc RAM)0.0035s0 B
[9] html entities ~ plain0.0150s0 B
[10] html entities ~ entities0.0171s0 B
[11] func int addition0.0143s0 B
[12] func float addition0.0147s0 B
[13] func string creation0.0138s0 B
[14] func string cat0.0239s0 B
[15] reference string cat0.0145s0 B
[16] reference int increment0.0139s0 B
[17] EVAL linear float increment0.0821s0 B
[18] EVAL linear int increment 0.0811s0 B
[19] EVAL linear float addition0.0849s0 B
[20] EVAL string creation0.0856s0 B
[21] EVAL string concat0.0897s0 B
[22] for loop1.8264s0 B
[23] foreach ($v only) loop0.9435s0 B
[24] while list0.0160s0 B
[25] foreach ($k=>$v) loop1.5119s0 B
[26] simple array_key_exists0.0126s0 B
[27] isset0.0037s0 B
[28] in_array0.0130s0 B
[29] empty0.0032s0 B
[30] simple array_key_exists largeData1.1872s0 B
[31] isset largeData0.0032s0 B
[32] in_array largeData1.7328s0 B
[33] empty largeData0.0031s0 B
[34] largerData2 array_key_exists1,631.4933s0 B
[35] isset largeData20.0032s0 B
[36] largerData2 in_array1,650.6589s0 B
[37] empty largeData20.0032s0 B
[38] largerData3 array_key_exists17.4148s0 B
[39] empty largeData30.0035s0 B
[40] largerData3 isset0.0033s0 B
[41] largerData3 in_array20.8420s0 B
[42] largerData4 array_key_exists7.5653s0 B
[43] isset largeData40.0033s0 B
[44] largerData4 empty0.0033s0 B
[45] largerData4 in_array9.3922s0 B
[46] uniqid0.6567s0 B
[47] md50.0276s0 B
[48] sha10.0230s0 B
[49] sha2560.0259s0 B
[50] sha5120.0572s0 B
[51] tiger128,30.0270s0 B
[52] adler320.0186s0 B
[53] crc32b0.0186s0 B
[54] whirlpool0.0491s0 B
[55] haval224,30.0303s0 B
[56] strcmp by == match0.0033s0 B
[57] strcmp by == match 2vars0.0033s0 B
[58] strcmp by == nomatch0.0033s0 B
[59] strcmp by strcmp0.0141s0 B
[60] strcmp by !strcmp0.0138s0 B
[61] strcmp by strcmp 2vars0.0130s0 B
[62] strcmp by reg0.0405s0 B
[63] strcmp by strstr0.0143s0 B
[64] strcmp by preg_match 10.0197s0 B
[65] global obj method call0.0192s0 B
[66] local obj method call0.0189s0 B
[67] local obj method call0.0179s0 B
[68] via call_user_func_array0.0451s0 B
[69] if statement0.0046s0 B
[70] switch statement0.0042s0 B
[71] ternary statement0.0049s0 B

I don't understand why the section labelled 'EVAL linear float increament' is so slow or memory expensive.
*%* This PHP interpreter doesn't like this test item. I don't understand why the object reference magically doesn't work in this situation. Look at the source for more detail.