- []
- +=
- array_push()
使用したもの | 実行速度 (秒) |
---|---|
[] |
0.10734009742737 |
+= |
0.13818192481995 |
array_push() |
0.14035105705261 |
- +=
- array_merge()
- []
使用したもの | 実行速度 (秒) |
---|---|
+= |
0.15385508537292 |
array_merge() |
0.24352407455444 |
[] |
0.25776886940002 |
<?php | |
// []で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
$array[] = $i; | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.10734009742737 秒 | |
// +=で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
$array += array($i => $i); | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.13818192481995 秒 | |
// array_push()で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
array_push($array, $i); | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.14035105705261 秒 | |
// 結果 | |
// 1. [] 0.10734009742737 秒 | |
// 2. += 0.13818192481995 秒 | |
// 3. array_push() 0.14035105705261 秒 |
<?php | |
ini_set('memory_limit', '256M'); | |
// +=で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
$array += array($i => $i); | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.15385508537292 秒 | |
// array_merge()で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
array_merge($array, array($i => $i)); | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.24352407455444 秒 | |
// []で配列追加 | |
$array = array(0, 1, 2, 3, 4, 5); | |
$time_start = microtime(true); | |
for ($i=6; $i < 500000; $i++) { | |
$array[] = array($i => $i); | |
} | |
$time = microtime(true) - $time_start; | |
echo "{$time} 秒\n"; // 0.25776886940002 秒 | |
// 結果 | |
// 1. += 0.15385508537292 秒 | |
// 2. array_merge() 0.24352407455444 秒 | |
// 3. [] 0.25776886940002 秒 |