1
|
|
|
<?php |
2
|
|
|
require __DIR__ . '/../autoload.php'; |
3
|
|
|
|
4
|
|
|
use Fwlib\Test\Benchmark\Benchmark; |
5
|
|
|
use Fwlib\Util\UtilContainer; |
6
|
|
|
use Fwlib\Util\Uuid\GeneratorInterface; |
7
|
|
|
|
8
|
|
|
// Speed test for Uuid generate |
9
|
|
|
$count = 10000; |
10
|
|
|
|
11
|
|
|
$utilContainer = UtilContainer::getInstance(); |
12
|
|
|
$bm = new Benchmark(); |
13
|
|
|
$bm->setUtilContainer($utilContainer); |
14
|
|
|
|
15
|
|
|
$bm->start('Gen ' . $count . ' UUID'); |
16
|
|
|
$speed = 0; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
$uuidBase16 = $utilContainer->getUuidBase16(); |
20
|
|
|
$uuidBase36 = $utilContainer->getUuidBase36(); |
21
|
|
|
$uuidBase36Short = $utilContainer->getUuidBase36Short(); |
22
|
|
|
$uuidBase62 = $utilContainer->getUuidBase62(); |
23
|
|
|
|
24
|
|
|
$algorithms = [ |
25
|
|
|
'Base16', |
26
|
|
|
'Base36', |
27
|
|
|
'Base36Short', |
28
|
|
|
'Base62' |
29
|
|
|
]; |
30
|
|
|
$arSpeed = []; |
31
|
|
|
foreach ($algorithms as $k => $v) { |
32
|
|
|
$class = 'Fwlib\\Util\\Uuid\\' . $v; |
33
|
|
|
$instanceName = 'uuid' . $v; |
34
|
|
|
/** @var GeneratorInterface $instance */ |
35
|
|
|
$instance = $$instanceName; |
36
|
|
|
|
37
|
|
|
$v = str_pad($v, 11, ' ', STR_PAD_RIGHT); // For display later |
38
|
|
|
|
39
|
|
|
for ($i = 0; $i < $count; $i ++) { |
40
|
|
|
$instance->generate(); |
41
|
|
|
} |
42
|
|
|
$usedTime = $bm->mark("$v without check digit: average speed{$k}wt/s"); |
43
|
|
|
$arSpeed["speed{$k}wt"] = round($count / $usedTime * 1000); |
44
|
|
|
|
45
|
|
|
for ($i = 0; $i < $count; $i ++) { |
46
|
|
|
$instance->generate('', '', true); |
47
|
|
|
} |
48
|
|
|
$usedTime = $bm->mark("$v with check digit: average speed{$k}wo/s"); |
49
|
|
|
$arSpeed["speed{$k}wo"] = round($count / $usedTime * 1000); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Replace {speed} in result |
54
|
|
|
$rs = $bm->display(null, true); |
|
|
|
|
55
|
|
|
$rs = str_replace(array_keys($arSpeed), $arSpeed, $rs); |
56
|
|
|
|
57
|
|
|
echo $rs; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
$env = $utilContainer->getEnv(); |
61
|
|
|
$env->ecl('Base16 without check digit: ' . $uuidBase16->generate('10', null, false)); |
62
|
|
|
$env->ecl('Base16 with check digit: ' . $uuidBase16->generate('10', null, true)); |
63
|
|
|
|
64
|
|
|
$env->ecl('Base16 without check digit: ' . $uuidBase16->generateWithSeparator('10', null, false)); |
65
|
|
|
$env->ecl('Base16 with check digit: ' . $uuidBase16->generateWithSeparator('10', null, true)); |
66
|
|
|
|
67
|
|
|
$env->ecl('Base36 without check digit: ' . $uuidBase36->generate('10', null, false)); |
68
|
|
|
$env->ecl('Base36 with check digit: ' . $uuidBase36->generate('10', null, true)); |
69
|
|
|
|
70
|
|
|
$env->ecl('Base36Short without check digit: ' . $uuidBase36Short->generate('1', null, false)); |
71
|
|
|
$env->ecl('Base36Short with check digit: ' . $uuidBase36Short->generate('1', null, true)); |
72
|
|
|
|
73
|
|
|
$env->ecl('Base62 without check digit: ' . $uuidBase62->generate('10', null, false)); |
74
|
|
|
$env->ecl('Base62 with check digit: ' . $uuidBase62->generate('10', null, true)); |
75
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.