Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created February 10, 2012 15:58
Show Gist options
  • Save daGrevis/1790459 to your computer and use it in GitHub Desktop.
Save daGrevis/1790459 to your computer and use it in GitHub Desktop.
[bench] String concatenation versus printing string
<?php
echo '<div style="display: none;">';
$s1 = microtime(true);
for ($i = 0; $i < 1000000; ++$i) {
echo 'a'.'b';
}
$e1 = microtime(true) - $s1;
$s2 = microtime(true);
for ($i = 0; $i < 1000000; ++$i) {
echo 'a', 'b';
}
$e2 = microtime(true) - $s2;
echo '</div>';
echo '<br /><br />';
echo $e1;
echo '<br />';
echo $e2;
echo '<br />';
echo $e1 - $e2;
// esmu kruts
@daGrevis
Copy link
Author

0.35480618476868
0.31502389907837
0.039782285690308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment