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
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: