<?php function truncate(string &$text): void { if (is_numeric($text)) { $text = ltrim($text, '0'); } if (mb_strlen($text) <= 50) { return; } $text = mb_substr($text, 0, 50); } function truncate2(string &$text): void { if (is_numeric($text)) { $text = ltrim($text, '0'); } $text = mb_substr($text, 0, 50); } $x = 'fdbvfgbtrbwrbtrbrtwb'; $before = microtime(true); for ($i=0 ; $i<10000 ; $i++) { truncate($x); } $after = microtime(true); echo ($after-$before) . " sec\n"; $before = microtime(true); for ($i=0 ; $i<10000 ; $i++) { truncate2($x); } $after = microtime(true); echo ($after-$before) . " sec\n";
You have javascript disabled. You will not be able to edit any code.