- array_count_values: documentation ( source)
- microtime: documentation ( source)
- array_unique: documentation ( source)
- max: documentation ( source)
- sprintf: documentation ( source)
<?php
$constants = array(
'FOO' => 1,
'BAR' => 2,
'BAZ' => 3,
'FOO2' => 1,
'BAR2' => 2,
'BAZ2' => 3,
);
echo 'max+array_count_values: ';
$start = microtime(true);
for($i=0; $i<1000; $i++) {
$bool = (max(array_count_values($constants)) > 1);
}
$end = microtime(true);
echo sprintf('%F', $end-$start) . PHP_EOL;
echo 'count+array_unique+count: ';
$start = microtime(true);
for($i=0; $i<1000; $i++) {
$bool = (count($constants) > count(array_unique($constants)));
}
$end = microtime(true);
echo sprintf('%F', $end-$start) . PHP_EOL;