我測試的SplFixedArray建設有一週的日子的數組,我得到下面的結果:真的SplFixedArray執行比數組更好嗎?
<?php
$days = new SplFixedArray(7);
$days[0] = "Monday";
$days[1] = "Tuesday";
$days[2] = "Wednesday";
$days[3] = "Thursday";
$days[4] = "Friday";
$days[5] = "Saturday";
$days[6] = "Sunday";
echo memory_get_peak_usage() . "\n"; //Returns 327688
echo memory_get_usage() . "\n"; //Returns 327140
echo memory_get_peak_usage(true) . "\n"; //Returns 524288
echo memory_get_usage(true) . "\n"; //Returns 524288
與傳統陣列:
<?php
$days = array();
$days[0] = "Monday";
$days[1] = "Tuesday";
$days[2] = "Wednesday";
$days[3] = "Thursday";
$days[4] = "Friday";
$days[5] = "Saturday";
$days[6] = "Sunday";
echo memory_get_peak_usage() . "\n"; //Returns 327528
echo memory_get_usage() . "\n"; //Returns 326820
echo memory_get_peak_usage(true) . "\n"; //Returns 524288
echo memory_get_usage(true) . "\n"; //Returns 524288
它使你的感覺?
你的創建對象和數組...你想要什麼? – voodoo417 2012-08-06 11:53:47
該陣列可能太小而無法體會其差異。嘗試對較大的數組進行基準測試,這就是SplFixedArray無論如何。 – Mahn 2012-08-06 12:12:56