Last active
June 20, 2022 14:27
-
-
Save vitormattos/e242d41f92dc1ae4548c7311644fb287 to your computer and use it in GitHub Desktop.
benchmark between string casting and srtcal
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 | |
/** | |
* How to use? | |
* | |
* Run: | |
* php test.php <number of loops> | |
* Example: | |
* php test.php 100000 | |
*/ | |
$count = $argv[1]; | |
echo "string cast\n"; | |
for ($a=0; $a < 3; $a++) { | |
$time_start = microtime(true); | |
for ($i=0; $i < $count; $i++) { | |
$test = (string) $count; | |
} | |
echo number_format(microtime(true) - $time_start, 3) . PHP_EOL; | |
} | |
echo "strval\n"; | |
for ($a=0; $a < 3; $a++) { | |
$time_start = microtime(true); | |
for ($i=0; $i < $count; $i++) { | |
$test = strval($count); | |
} | |
echo number_format(microtime(true) - $time_start, 3) . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My results: