PHP5 Benchmark
PHP: version 5.0.5 PC: Celeron 2.0Mhz / 512Mb | |||||
| |||||
Creating int array[100 000] | |||||
PHP 5 Benchmark :: for vs while | |||||
code |
[ms] |
speed rate |
faster | ||
for($i=0;$i<10000;$i++) {..} | 0.087 |
x1 | |||
while($i<10000) {..} | 0.086 |
x1.01 | |||
compare with php 4 | |||||
Reading int array[100 000] | |||||
PHP 5 Benchmark :: while vs foreach vs for | |||||
code |
[ms] |
speed rate |
faster | ||
foreach($arr1 as $vl) {..} | 0.171 |
x1.95 | |||
while(list(,$vl = each($arr2)) {..} | 0.335 |
x1 | |||
for($i=0;$i<10000;$i++) {..} | 0.163 |
x2.05 | |||
compare with php 4 | |||||
Reading apache log (16Mb) | |||||
PHP 5 Benchmark :: file vs file_get_content vs fread | |||||
code |
[ms] |
speed rate |
faster | ||
$a = file("t1.log"); | 0.274 |
x1 | |||
$b = file_get_contents("t1.log"); | 0.121 |
x2.26 | |||
.. $c = fread($hdl, $size); .. | 0.141 |
x1.94 | |||
compare with php 4 | |||||
Parse vars names [100 000] | |||||
PHP 5 Benchmark :: "test$i" vs "test".$i vs ‘test’.$i | |||||
code |
[ms] |
speed rate |
faster | ||
for(…) {$c = "test$i";} |
0.354 |
x1 | |||
for(…) {$c = "test".$i;} |
0.236 |
x1.5 | |||
for(…) {$c = ‘test’.$i;} |
0.236 |
x1.5 | |||
compare with php 4 | |||||
Parse and find text from apache log (32Mb) | |||||
PHP 5 Benchmark :: ereg vs preg_match | |||||
code |
[ms] |
speed rate |
faster | ||
eregi("2005:03:04",$txt); | 3.521 |
x1 | |||
preg_match("/2005:03:04/im",$txt); | 0.735 |
x4.7 | |||
compare with php 4 | |||||
Split text apache log 200Kb (contain 2000 "-") | |||||
PHP 5 Benchmark :: split vs explode | |||||
code |
[ms] |
speed rate |
faster | ||
split("-",$txt); | 1.573 |
x1 | |||
explode("-",$txt); |
0.197 |
x8 | |||
compare with php 4 | |||||
Count array size. $arr = int[100 000] | |||||
PHP 5 Benchmark :: count vs sizeof | |||||
code |
[ms] |
speed rate |
faster | ||
for($i=0;$i<count($arr);$i++) | 0.276 |
x1 | |||
for($i=0;$i<sizeof($arr);$i++) | 0.268 |
x1.02 | |||
compare with php 4 | |||||
Create object by Ref (loop 100 000) | |||||
PHP 5 Benchmark :: with ref vs without ref | |||||
code |
[ms] |
speed rate |
faster | ||
(…) {$j = & new TestClass();} |
1.180 |
x1 | |||
(…) {$j = new TestClass(); } | 1.291 |
x1.09 | |||
compare with php 4 | |||||
Random number generator (loop 100 000) | |||||
PHP 5 Benchmark :: srand vs mt_srand | |||||
code |
[ms] |
speed rate |
faster | ||
(…) { srand(); } | 0.193 |
x1 | |||
(…) { mt_srand(); } | 0.989 |
x5.12 | |||
compare with php 4 | |||||
Calculate hash (loop 100 000) | |||||
PHP 5 Benchmark :: srand vs mt_srand | |||||
code |
[ms] |
speed rate |
faster | ||
(…) { md5($i."byster.net".$i); } | 1.365 |
x1 | |||
(…) { sha1($i."byster.net".$i);} | 1.662 |
x1.2 | |||
compare with php 4 |