<?php
$count = 100;
$start = microtime(true);
for ($i = 0; $i < $count; $i++) {
$str = "abc";
$str = preg_replace_callback('/a/', 'strtoupper', $str);
$str = preg_replace_callback('/b/', 'strtoupper', $str);
$str = preg_replace_callback('/c/', 'strtoupper', $str);
$str = preg_replace_callback('/a/', 'strtolower', $str);
$str = preg_replace_callback('/b/', 'strtolower', $str);
$str = preg_replace_callback('/c/', 'strtolower', $str);
}
echo "Completed in " . (microtime(true) - $start) . " Seconds\n";
$start = microtime(true);
for ($i = 0; $i < $count; $i++) {
$str = "abc";
$str = preg_replace(array(
'/a/e',
'/b/e',
'/c/e',
'/a/e',
'/b/e',
'/c/e',
),
array(
'strtoupper(\'$1\')',
'strtoupper(\'$1\')',
'strtoupper(\'$1\')',
'strtolower(\'$1\')',
'strtolower(\'$1\')',
'strtolower(\'$1\')',
),
$str
);
}
echo "Completed in " . (microtime(true) - $start) . " Seconds\n";
preferences:
25.48 ms | 402 KiB | 5 Q