There is a major performance issue when using in-object array\'s as a property versus using a global php array variable, why?
To benchmark this problem I created the fol
I can't post this all in a comment, so this is more of an observation than an answer. It looks like SplObjectStorage is fairly slow. Also that array_push is a lot faster than $array[] = 'item';
Disclaimer: Apologies for the sloppy code :)
data[] = $obj;
}
break;
case 4:
class Test {
public static $data = array();
}
$s = new Test;
for ($i = 0; $i < $iteration; $i++) {
$obj = new stdClass;
$s->data[] = $obj;
}
break;
case 5:
class Test {
public $data = array();
}
$s = new Test;
for ($i = 0; $i < $iteration; $i++) {
$obj = new stdClass;
array_push($s->data, $obj);
}
break;
default:
echo 'Type in ?test=#';
}
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 6);
echo 'Page generated in '.$total_time.' seconds.';