Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 77 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
BenchUuidConversions | |
0.00% |
0 / 71 |
|
0.00% |
0 / 8 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
2 | |||
oldhex2timestamp | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
oldalphadecimal2timestamp | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
case1 | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
case2 | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
case3 | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
case4 | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Maintenance; |
4 | |
5 | use Flow\Model\UUID; |
6 | use MediaWiki\Maintenance\Benchmarker; |
7 | |
8 | $IP = getenv( 'MW_INSTALL_PATH' ); |
9 | if ( $IP === false ) { |
10 | $IP = __DIR__ . '/../../..'; |
11 | } |
12 | |
13 | require_once "$IP/maintenance/includes/Benchmarker.php"; |
14 | |
15 | /** |
16 | * @ingroup Benchmark |
17 | */ |
18 | class BenchUuidConversions extends Benchmarker { |
19 | public function __construct() { |
20 | parent::__construct(); |
21 | $this->addDescription( 'Benchmark uuid timestamp extraction implementations' ); |
22 | $this->requireExtension( 'Flow' ); |
23 | } |
24 | |
25 | public function execute() { |
26 | // sample values slightly different to avoid |
27 | // UUID internal caching |
28 | $alpha = UUID::hex2alnum( '0523f95ac547ab45266762' ); |
29 | $binary = UUID::hex2bin( '0523f95af547ab45266762' ); |
30 | $hex = '0423f95af547ab45266762'; |
31 | |
32 | // benchmarker requires we pass an object |
33 | $id = UUID::create(); |
34 | |
35 | $this->bench( [ |
36 | [ |
37 | 'function' => [ $id, 'bin2hex' ], |
38 | 'args' => [ $binary ], |
39 | ], |
40 | [ |
41 | 'function' => [ $id, 'alnum2hex' ], |
42 | 'args' => [ $alpha ], |
43 | ], |
44 | [ |
45 | 'function' => [ $id, 'hex2bin' ], |
46 | 'args' => [ $hex ], |
47 | ], |
48 | [ |
49 | 'function' => [ $id, 'hex2alnum' ], |
50 | 'args' => [ $hex ], |
51 | ], |
52 | [ |
53 | 'function' => [ $id, 'hex2timestamp' ], |
54 | 'args' => [ $hex ], |
55 | ], |
56 | [ |
57 | 'function' => [ $this, 'oldhex2timestamp' ], |
58 | 'args' => [ $hex ], |
59 | ], |
60 | [ |
61 | 'function' => [ $this, 'oldalphadecimal2timestamp' ], |
62 | 'args' => [ $alpha ], |
63 | ], |
64 | [ |
65 | 'function' => [ $this, 'case1' ], |
66 | 'args' => [ $binary ], |
67 | ], |
68 | [ |
69 | 'function' => [ $this, 'case2' ], |
70 | 'args' => [ $binary ], |
71 | ], |
72 | [ |
73 | 'function' => [ $this, 'case3' ], |
74 | 'args' => [ $alpha ], |
75 | ], |
76 | [ |
77 | 'function' => [ $this, 'case4' ], |
78 | 'args' => [ $alpha ], |
79 | ], |
80 | ] ); |
81 | |
82 | // @fixme Find a replacement for this (removed from core in 1.29) |
83 | // $this->output( $this->getFormattedResults() ); |
84 | } |
85 | |
86 | public function oldhex2timestamp( $hex ) { |
87 | $bits = \Wikimedia\base_convert( $hex, 16, 2, 88 ); |
88 | $msTimestamp = (int)\Wikimedia\base_convert( substr( $bits, 0, 46 ), 2, 10 ); |
89 | return intval( $msTimestamp / 1000 ); |
90 | } |
91 | |
92 | public function oldalphadecimal2timestamp( $alpha ) { |
93 | $bits = \Wikimedia\base_convert( $alpha, 36, 2, 88 ); |
94 | $msTimestamp = (int)\Wikimedia\base_convert( substr( $bits, 0, 46 ), 2, 10 ); |
95 | return intval( $msTimestamp / 1000 ); |
96 | } |
97 | |
98 | /** |
99 | * Common case 1: binary from database to alpha and timestamp. |
100 | * @param string $binary |
101 | */ |
102 | public function case1( $binary ) { |
103 | // clone to avoid internal object caching |
104 | $id = clone UUID::create( $binary ); |
105 | $id->getAlphadecimal(); |
106 | $id->getTimestampObj(); |
107 | } |
108 | |
109 | /** |
110 | * Common case 2: binary from database to timestamp and alpha. |
111 | * Probably same as case 1, but who knows. |
112 | * @param string $binary |
113 | */ |
114 | public function case2( $binary ) { |
115 | // clone to avoid internal object caching |
116 | $id = clone UUID::create( $binary ); |
117 | $id->getTimestampObj(); |
118 | $id->getAlphadecimal(); |
119 | } |
120 | |
121 | /** |
122 | * Common case 3: alphadecimal from cache to timestamp and binary. |
123 | * @param string $alpha |
124 | */ |
125 | public function case3( $alpha ) { |
126 | // clone to avoid internal object caching |
127 | $id = clone UUID::create( $alpha ); |
128 | $id->getBinary(); |
129 | $id->getTimestampObj(); |
130 | } |
131 | |
132 | /** |
133 | * Common case 4: alphadecimal from cache to bianry and timestamp. |
134 | * @param string $alpha |
135 | */ |
136 | public function case4( $alpha ) { |
137 | // clone to avoid internal object caching |
138 | $id = clone UUID::create( $alpha ); |
139 | $id->getTimestampObj(); |
140 | $id->getBinary(); |
141 | } |
142 | } |
143 | |
144 | $maintClass = BenchUuidConversions::class; |
145 | require_once RUN_MAINTENANCE_IF_MAIN; |