<?php
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
};
$anon_cmp = function ($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
};
$count = 1000000;
$time = microtime(true);
for ($i = 0; $i < $count; $i++) {
$arr = [9, 7, 1, 5, 7, 12, 3, 9, 2];
usort($arr, $anon_cmp);
}
$time = microtime(true) - $time;
echo "Time: {$time}</br>";
$time = microtime(true);
for ($i = 0; $i < $count; $i++) {
$arr = [9, 7, 1, 5, 7, 12, 3, 9, 2];
usort($arr, 'cmp');
}
$time = microtime(true) - $time;
echo "Time: {$time}</br>";
Time: 30.63868689537
Time: 20.771629095078