Last active
December 30, 2015 11:59
-
-
Save GhostToast/7826211 to your computer and use it in GitHub Desktop.
micro optimization!! each test now involves many tests, so average is calculated and indicated in comments. one test was run at a time.
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 | |
$foo = 'foo'; | |
$bar = 'bar'; | |
$foobar = 'foobar'; | |
$string = ''; | |
$tests = array(); | |
for ($z = 0; $z<1000; $z++){ | |
$startTime = microtime(true); | |
for ($i = 0; $i<1000; $i++) { | |
// $string .= 'this ' . ' is ' . $foo . ', this is ' . $bar . ' and this is ' . $foobar; // 0.4931318783 Milliseconds | |
// $string .= "this is $foo, this is $bar and this is $foobar"; // 0.4040865907 Milliseconds | |
// $string .= "this is {$foo}, this is {$bar} and this is {$foobar}"; // 0.4096872842 Milliseconds | |
} | |
$tests[] = number_format(( microtime(true) - $startTime), 10) * 1000; | |
} | |
echo array_sum($tests) / count($tests); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment