array_map与回路和操作
用:
for($i=1; $i<= 10000; ++$i) {
$arrayOfNumbers[] = rand(1, 99999);
}
有人可以解释为什么会有这样的速度差异吗:
array_map(array($maxHeap, 'insert'), $arrayOfNumbers);
# Avg Time: 0.92856907844543s
# against
foreach($arrayOfNumbers as $number) {
$maxHeap->insert($number);
}
# Avg Time: 1.3148670101166
$maxHeap
成为对象class MaxHeap extends SplMaxHeap