[development] Time for a new chapter of an endless debate

Angela Byron drupal-devel at webchick.net
Mon Jul 3 02:53:41 UTC 2006


Here are some more, at the request of dopry:

PHP 4.4.2:
Send 1,000 objects with 500 properties to a function by value: 1400.54ms
Send 1,000 arrays with 500 keys to a function by value: 1033.07ms
Send 1,000 objects with 25 properties to a function by value: 78.26ms
Send 1,000 arrays with 25 keys to a function by value: 51.39ms
Send 1,000 objects with 500 properties to a function by reference:  
1392.78ms
Send 1,000 arrays with 500 keys to a function by reference: 1067.2ms
Send 1,000 objects with 25 properties to a function by reference: 79.5ms
Send 1,000 arrays with 25 keys to a function by reference: 50.37ms

PHP 5.1.2:
Send 1,000 objects with 500 properties to a function by value: 734.31ms
Send 1,000 arrays with 500 keys to a function by value: 475.04ms
Send 1,000 objects with 25 properties to a function by value: 40.94ms
Send 1,000 arrays with 25 keys to a function by value: 22.07ms
Send 1,000 objects with 500 properties to a function by reference:  
698.29ms
Send 1,000 arrays with 500 keys to a function by reference: 472.9ms
Send 1,000 objects with 25 properties to a function by reference:  
36.54ms
Send 1,000 arrays with 25 keys to a function by reference: 25.43ms

Code:

<?php


echo "Send 1,000 objects with 500 properties to a function by value: ";
timer_start('object_by_val');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 500; $j++) {
     $obj = new stdClass();
     $prop = (string)$j;
     $obj->$prop = $j;
   }
   do_nothing_val($obj);
}
$stop = timer_stop('object_by_val');
echo $stop['time'] .'ms <br />';

echo "Send 1,000 arrays with 500 keys to a function by value: ";
timer_start('array_by_val');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 500; $j++) {
     $arr = array();
     $key = (string)$j;
     $array[$key] = $j;
   }
   do_nothing_val($arr);
}
$stop = timer_stop('array_by_val');
echo $stop['time'] .'ms <br />';

echo "Send 1,000 objects with 25 properties to a function by value: ";
timer_start('small_object_by_val');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 25; $j++) {
     $obj = new stdClass();
     $prop = (string)$j;
     $obj->$prop = $j;
   }
   do_nothing_val($obj);
}
$stop = timer_stop('small_object_by_val');
echo $stop['time'] .'ms <br />';

echo "Send 1,000 arrays with 25 keys to a function by value: ";
timer_start('small_array_by_val');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 25; $j++) {
     $arr = array();
     $key = (string)$j;
     $array[$key] = $j;
   }
   do_nothing_val($arr);
}
$stop = timer_stop('small_array_by_val');
echo $stop['time'] .'ms <br />';


echo "Send 1,000 objects with 500 properties to a function by  
reference: ";
timer_start('object_by_ref');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 500; $j++) {
     $obj = new stdClass();
     $prop = (string)$j;
     $obj->$prop = $j;
   }
   do_nothing_val($obj);
}
$stop = timer_stop('object_by_ref');
echo $stop['time'] .'ms <br />';

echo "Send 1,000 arrays with 500 keys to a function by reference: ";
timer_start('array_by_ref');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 500; $j++) {
     $arr = array();
     $key = (string)$j;
     $array[$key] = $j;
   }
   do_nothing_ref($arr);
}
$stop = timer_stop('array_by_ref');
echo $stop['time'] .'ms <br />';



echo "Send 1,000 objects with 25 properties to a function by  
reference: ";
timer_start('small_object_by_ref');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 25; $j++) {
     $obj = new stdClass();
     $prop = (string)$j;
     $obj->$prop = $j;
   }
   do_nothing_ref($obj);
}
$stop = timer_stop('small_object_by_ref');
echo $stop['time'] .'ms <br />';

echo "Send 1,000 arrays with 25 keys to a function by reference: ";
timer_start('small_array_by_ref');
for ($i = 0; $i < 1000; $i++) {
   for ($j = 0; $j < 25; $j++) {
     $arr = array();
     $key = (string)$j;
     $array[$key] = $j;
   }
   do_nothing_ref($arr);
}
$stop = timer_stop('small_array_by_ref');
echo $stop['time'] .'ms <br />';



function do_nothing_val($thing) {
   return $thing;
}

function do_nothing_ref(&$thing) {
   return $thing;
}

?>



More information about the development mailing list