The SplFixedArray class provides the main functionalities of array. The main differences between a SplFixedArray and a normal PHP array is that the SplFixedArray is of fixed length and allows only integers within the range as indexes. The advantage is that it allows a faster array implementation.
大概快40%。
可以使用pear的Benchmark來比較兩種之間執行時間上的差别(少資料量測試,多資料量如100000也差不多,記憶體占用也具有優勢):
mark 03 1310263548.29697000 0.000016 11.27%
mark 04 1310263548.29699600 0.000026 18.31%
require_once 'Benchmark/Timer.php';
$timer = new Benchmark_Timer();
$timer->start();
$timer->setMarker('marker 01');
$arr = new SplFixedArray(5);
$arr[0] = 'one';
$arr[1] = 'two';
$arr[2] = 'three';
$arr[3] = 'four';
$arr[4] = 'five';
$timer->setMarker('mark 02');
$arr2 = array('one','two','three','four','five');
$timer->setMarker('mark 03');
print_r($arr);
$timer->setMarker('mark 04');
print_r($arr2);