Created
February 21, 2015 20:21
-
-
Save frak/d7931facf5ba2b4d835e to your computer and use it in GitHub Desktop.
Please don't use sprintf...
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
<?php | |
$maxiter = 10000000; | |
$value = "1234"; | |
$time_start = microtime(true); | |
for ($i = 0; $i < $maxiter; ++$i) { | |
$string = "This is " . $value; | |
} | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo "concatenate in $time seconds\n"; | |
$time_start = microtime(true); | |
for ($i = 0; $i < $maxiter; ++$i) { | |
$string = "This is {$value}"; | |
} | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo "interpolated in $time seconds\n"; | |
$time_start = microtime(true); | |
for ($i = 0; $i < $maxiter; ++$i) { | |
$string = sprintf('This is %s', $value); | |
} | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo "sprintf in $time seconds\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment