<?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";
}
- Output for 8.2.0, 8.2.2, 8.2.4, 8.2.7, 8.2.9, 8.2.11, 8.2.14, 8.2.16, 8.2.20, 8.2.22, 8.2.25, 8.3.4, 8.3.6, 8.3.9, 8.4.1
- str_replace
- Output for 8.2.1, 8.2.3, 8.2.5 - 8.2.6, 8.2.8, 8.2.10, 8.2.12 - 8.2.13, 8.2.15, 8.2.17 - 8.2.19, 8.2.21, 8.2.23 - 8.2.24, 8.2.26, 8.3.0 - 8.3.3, 8.3.5, 8.3.7 - 8.3.8, 8.3.10 - 8.3.14
- strtr
preferences:
42.98 ms | 409 KiB | 5 Q