- microtime: documentation ( source)
- strtr: documentation ( source)
- asort: documentation ( source)
- str_replace: documentation ( source)
- array_key_first: documentation ( source)
<?php
$values = [];
const ITERATIONS = 100000;
$start = microtime(true);
for ($i = 0; $i < ITERATIONS; $i++) {
strtr('1_000_000', ['_' => '']);
strtr('1000000', ['_' => '']);
}
$values['strtr'] = microtime(true) - $start;
$start = microtime(true);
for ($i = 0; $i < ITERATIONS; $i++) {
str_replace('_', '', '1_000_000');
str_replace('_', '', '1000000');
}
$values['str_replace'] = (microtime(true) - $start);
asort($values);
echo array_key_first($values). "\n";
foreach ($values as $key => $val) {
// echo "\n".str_pad($key, 14, ' ') . number_format($val * 1000 / ITERATIONS, 5) . " ms / k";
}