<?php
$count = 100;
$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";
$start = microtime(true);
for ($i = 0; $i < $count; $i++) {
$str = "abc";
$str = preg_replace_callback('/a/', function($a) { return strtoupper($a[0]); }, $str);
$str = preg_replace_callback('/b/', function($a) { return strtoupper($a[0]); }, $str);
$str = preg_replace_callback('/c/', function($a) { return strtoupper($a[0]); }, $str);
$str = preg_replace_callback('/a/', function($a) { return strtolower($a[0]); }, $str);
$str = preg_replace_callback('/b/', function($a) { return strtolower($a[0]); }, $str);
$str = preg_replace_callback('/c/', function($a) { return strtolower($a[0]); }, $str);
}
echo "Completed in " . (microtime(true) - $start) . " Seconds\n";
preferences:
30.33 ms | 402 KiB | 5 Q