Код (Text): dev:~# php test.php 1 : 0,44316291809082<br/> 2 : 0,69142580032349<br/> 3 : 0,38251399993896<br/> PHP: $t = microtime(true); for ($i = 0; $i < 100000; $i++) { sscanf($date_from, "%4s%2s%2s", $y, $m, $d); $date_to = $y.'.'.$m.'.'.$d; } echo '3 : '.(microtime(true) - $t)."<br/>\n";
PHP: <?php $date_from = '19810101'; $date_to = 'gggg.mm.dd'; $t = microtime(true); for ($i = 0; $i < 100000; $i++) { $a = str_split($date_from, 2); $date_to = $a[0].$a[1].'.'.$a[2].'.'.$a[3]; } echo '1 : '.(microtime(true) - $t).'<br>'; $t = microtime(true); for ($i = 0; $i < 100000; $i++) { $year = substr($date_from, 0, 4); $month = substr($date_from, 4, 2); $day = substr($date_from, 6, 2); $date_to = $year.'.'.$month.'.'.$day; } echo '2 : '.(microtime(true) - $t).'<br>'; $t = microtime(true); for ($i = 0; $i < 100000; $i++) { $date_to = date('d.m.Y', strtotime($date_from)); } echo '3 : '.(microtime(true) - $t).'<br>'; $t = microtime(true); for ($i = 0; $i < 100000; $i++) { sscanf($date_from, "%4s%2s%2s", $y, $m, $d); $date_to = $y.'.'.$m.'.'.$d; } echo '4 : '.(microtime(true) - $t)."<br/>\n"; ?>
Apelsin wins! Topic clos. Вот кстати можем наблюдать прямую трансляцию с ютуба как Апельсинкин радуется и ликует у себя на хате.