Last active
October 10, 2015 21:58
-
-
Save vlakoff/3757671 to your computer and use it in GitHub Desktop.
Optimizing character_limiter() of CodeIgniter's text helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/bcit-ci/CodeIgniter/pull/1750 | |
$nb = 1000; | |
$str = str_repeat('<lorem ipsum here>' . "\n", 10); | |
$t1 = microtime(true); | |
for ($i = $nb; $i--; ) { | |
preg_replace('/\s+/', ' ', $str); | |
} | |
$t2 = microtime(true); | |
for ($i = $nb; $i--; ) { | |
preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); | |
} | |
$t3 = microtime(true); | |
echo $t2 - $t1; | |
echo '<br>'; | |
echo $t3 - $t2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment