Created
November 15, 2022 19:30
-
-
Save trgino/3a97b7223b206b2c38fdd9cf013968df to your computer and use it in GitHub Desktop.
php rand vs mt_rand vs random_int fastest benchmark
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 | |
$a1=microtime(true); | |
foreach(range(1,10) as $a){ | |
echo mt_rand(0,100).PHP_EOL; | |
} | |
echo ':'.microtime(true)-$a1.PHP_EOL; | |
$a1=microtime(true); | |
foreach(range(1,10) as $a){ | |
echo random_int(0,100).PHP_EOL; | |
} | |
echo ':'.microtime(true)-$a1.PHP_EOL; | |
$a1=microtime(true); | |
foreach(range(1,10) as $a){ | |
echo rand(0,100).PHP_EOL; | |
} | |
echo ':'.microtime(true)-$a1.PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
59
17
25
95
70
51
15
73
43
70
:6.6995620727539E-5
92
43
4
0
98
4
76
85
79
23
:3.0040740966797E-5
11
47
52
35
43
69
52
54
18
86
:4.4107437133789E-5