-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
rand.bench.php
52 lines (48 loc) · 1.37 KB
/
rand.bench.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/** @var array<string, callable> */
return [
'rand' => function($multiplier = 1, $count = 1000000) {
$count = $count * $multiplier;
for ($i = 0; $i < $count; $i++) {
rand(0, $i);
}
return $i;
},
'mt_rand' => function($multiplier = 1, $count = 1000000) {
$count = $count * $multiplier;
for ($i = 0; $i < $count; $i++) {
mt_rand(0, $i);
}
return $i;
},
'random_int' => function($multiplier = 1, $count = 1000000) {
if (!function_exists('random_int')) {
return INF;
}
$count = $count * $multiplier;
for ($i = 0; $i < $count; $i++) {
random_int(0, $i);
}
return $i;
},
'random_bytes' => function($multiplier = 1, $count = 1000000) {
if (!function_exists('random_bytes')) {
return INF;
}
$count = $count * $multiplier;
for ($i = 0; $i < $count; $i++) {
random_bytes(32);
}
return $i;
},
'openssl_random_pseudo_bytes' => function($multiplier = 1, $count = 1000000) {
if (!function_exists('openssl_random_pseudo_bytes')) {
return INF;
}
$count = $count * $multiplier;
for ($i = 0; $i < $count; $i++) {
openssl_random_pseudo_bytes(32);
}
return $i;
},
];