Created
February 8, 2010 13:19
-
-
Save tobiassjosten/298129 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
// $ php -f tostring_helper_benchmark.php | |
// 0.877526044846 <- Arrays are slooow | |
// First: 0.352955102921 | |
// Second: 0.354468107224 <- substr() way takes a .0015s penalty | |
$time = microtime(true); | |
$html=array(); | |
for ($i=1; $i<1000000; $i++) | |
{ | |
$html[] = 'asdf'; | |
} | |
$html = implode(' ', $html); | |
print (microtime(true)-$time)."\n"; | |
$time = microtime(true); | |
$html=''; | |
for ($i=1; $i<1000000; $i++) | |
{ | |
$html .= ' asdf'; | |
} | |
print 'First: '.(microtime(true)-$time)."\n"; | |
$time = microtime(true); | |
$html=''; | |
for ($i=1; $i<1000000; $i++) | |
{ | |
$html .= ' asdf'; | |
} | |
if (!empty($html)) | |
{ | |
$html = substr($html, 1); | |
} | |
print 'Second: '.(microtime(true)-$time)."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment