Created
June 5, 2018 16:02
-
-
Save ammarfaizi2/a02cb5a2d75e13482e08b692078f992a to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @author Ammar Faizi <[email protected]> | |
* @license MIT | |
* @link https://t.me/laravelindonesia/111952 | |
*/ | |
for ($i=0; $i<10; $i++) { | |
echo "Test ".$i."\n"; | |
$start = microtime(true); | |
$a = "TR".date("ym"); | |
$no = 1; | |
$string = $no ." = ". $a.str_repeat("0", 3 - strlen($no)).$no.PHP_EOL; | |
$no = 10; | |
$string = $no ." = ". $a.str_repeat("0", 3 - strlen($no)).$no.PHP_EOL; | |
$no = 100; | |
$string = $no ." = ". $a.str_repeat("0", 3 - strlen($no)).$no.PHP_EOL; | |
$end = microtime(true); | |
echo "str_repeat+strlen = ". number_format($t1 = $end - $start, 15)."\n"; | |
$start = microtime(true); | |
$string = "TR".date("ym") . sprintf('%03d', 1); | |
$string = "TR".date("ym") . sprintf('%03d', 10); | |
$string = "TR".date("ym") . sprintf('%03d', 100); | |
$end = microtime(true); | |
echo "sprintf = ". number_format($t2 = $end - $start, 15)."\n"; | |
echo "Which faster? ".($t2 > $t1 ? "str_repeat+strlen" : "sprintf")."\n"; | |
echo "Timediff = ".(number_format(abs($t2-$t1), 15))."\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment