1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TreeMap benchmark class |
5
|
|
|
* |
6
|
|
|
* @author Christophe Demko <[email protected]> |
7
|
|
|
* @copyright Copyright (C) 2012-2023 Christophe Demko. All rights reserved. |
8
|
|
|
* |
9
|
|
|
* @license BSD 3-Clause License |
10
|
|
|
* |
11
|
|
|
* This file is part of the php-sorted-collections package https://github.com/chdemko/php-sorted-collections |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Declare chdemko\SortedCollectionBenchmark namespace |
15
|
|
|
namespace chdemko\SortedCollectionBenchmark; |
16
|
|
|
|
17
|
|
|
use chdemko\SortedCollection\TreeMap; |
18
|
|
|
use chdemko\SortedCollection\ReversedMap; |
19
|
|
|
use chdemko\SortedCollection\SubMap; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* TreeMap benchmark class |
23
|
|
|
* |
24
|
|
|
* @since 1.0.5 |
25
|
|
|
*/ |
26
|
|
|
class TreeMapBench |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var TreeMap The tree map |
30
|
|
|
* |
31
|
|
|
* @since 1.0.5 |
32
|
|
|
*/ |
33
|
|
|
protected $tree; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var SortedMap The sorted map |
|
|
|
|
37
|
|
|
* |
38
|
|
|
* @since 1.0.5 |
39
|
|
|
*/ |
40
|
|
|
protected $data; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Provider for counts |
44
|
|
|
* |
45
|
|
|
* @return iterator Iterator on count |
|
|
|
|
46
|
|
|
* |
47
|
|
|
* @since 1.0.5 |
48
|
|
|
*/ |
49
|
|
|
public function provideCounts() |
50
|
|
|
{ |
51
|
|
|
yield array('count' => 100); |
|
|
|
|
52
|
|
|
yield array('count' => 1000); |
53
|
|
|
yield array('count' => 10000); |
54
|
|
|
yield array('count' => 100000); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Provider for counts |
59
|
|
|
* |
60
|
|
|
* @return iterator Iterator on type |
61
|
|
|
* |
62
|
|
|
* @since 1.0.5 |
63
|
|
|
*/ |
64
|
|
|
public function provideTypes() |
65
|
|
|
{ |
66
|
|
|
yield array('type' => 'tree'); |
|
|
|
|
67
|
|
|
yield array('type' => 'reversed'); |
68
|
|
|
yield array('type' => 'sub', 'from' => 0.30, 'to' => 0.70); |
69
|
|
|
yield array('type' => 'sub', 'from' => 0.40, 'to' => 0.80); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Create the tree map. |
74
|
|
|
* |
75
|
|
|
* @param array $params Array of parameters |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
* |
79
|
|
|
* @since 1.0.5 |
80
|
|
|
*/ |
81
|
|
|
public function init($params) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$this->tree = TreeMap::create(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Create the sorted map. |
88
|
|
|
* |
89
|
|
|
* @param array $params Array of parameters |
90
|
|
|
* |
91
|
|
|
* @return void |
92
|
|
|
* |
93
|
|
|
* @since 1.0.5 |
94
|
|
|
*/ |
95
|
|
|
public function data($params) |
96
|
|
|
{ |
97
|
|
|
if (isset($params['type'])) { |
98
|
|
|
switch ($params['type']) { |
99
|
|
|
case 'tree': |
100
|
|
|
$this->data = $this->tree; |
|
|
|
|
101
|
|
|
break; |
102
|
|
|
case 'reversed': |
103
|
|
|
$this->data = ReversedMap::create($this->tree); |
104
|
|
|
break; |
105
|
|
|
case 'sub': |
106
|
|
|
if (isset($params['from']) && isset($params['to'])) { |
107
|
|
|
$this->data = SubMap::create( |
108
|
|
|
$this->tree, |
109
|
|
|
(int) ($params['from'] * $params['count']), |
110
|
|
|
(int) ($params['to'] * $params['count']) |
111
|
|
|
); |
112
|
|
|
} else { |
113
|
|
|
$this->data = SubMap::create( |
114
|
|
|
$this->tree, |
115
|
|
|
null, |
116
|
|
|
null |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
break; |
120
|
|
|
} |
121
|
|
|
} else { |
122
|
|
|
$this->data = $this->tree; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Clear the tree map. |
128
|
|
|
* |
129
|
|
|
* @param array $params Array of parameters |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
* |
133
|
|
|
* @since 1.0.5 |
134
|
|
|
*/ |
135
|
|
|
public function finish($params) |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
$this->tree->clear(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @BeforeMethods({"init", "data"}) |
142
|
|
|
* @AfterMethods({"finish"}) |
143
|
|
|
* @Revs(5) |
144
|
|
|
* @ParamProviders({"provideCounts"}) |
145
|
|
|
* |
146
|
|
|
* @param array $params Array of parameters |
147
|
|
|
* |
148
|
|
|
* @return void |
149
|
|
|
* |
150
|
|
|
* @since 1.0.5 |
151
|
|
|
*/ |
152
|
|
|
public function benchFill($params) |
153
|
|
|
{ |
154
|
|
|
for ($i = 0; $i < $params['count']; $i++) { |
155
|
|
|
$this->tree[$i] = $i; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @BeforeMethods({"init", "benchFill", "data"}) |
161
|
|
|
* @AfterMethods({"finish"}) |
162
|
|
|
* @Revs(5) |
163
|
|
|
* @ParamProviders({"provideCounts", "provideTypes"}) |
164
|
|
|
* |
165
|
|
|
* @param array $params Array of parameters |
166
|
|
|
* |
167
|
|
|
* @return void |
168
|
|
|
* |
169
|
|
|
* @since 1.0.5 |
170
|
|
|
*/ |
171
|
|
|
public function benchSearch($params) |
172
|
|
|
{ |
173
|
|
|
if (isset($params['from'])) { |
174
|
|
|
$min = (int) ($params['from'] * $params['count']); |
175
|
|
|
} else { |
176
|
|
|
$min = 0; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
if (isset($params['to'])) { |
180
|
|
|
$max = (int) ($params['to'] * $params['count']); |
181
|
|
|
} else { |
182
|
|
|
$max = $params['count']; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
for ($i = $min; $i < $max; $i++) { |
186
|
|
|
$value = $this->data[$i]; |
|
|
|
|
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @BeforeMethods({"init", "benchFill", "data"}) |
192
|
|
|
* @AfterMethods({"finish"}) |
193
|
|
|
* @Revs(5) |
194
|
|
|
* @ParamProviders({"provideCounts"}) |
195
|
|
|
* |
196
|
|
|
* @param array $params Array of parameters |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
* |
200
|
|
|
* @since 1.0.5 |
201
|
|
|
*/ |
202
|
|
|
public function benchClean($params) |
203
|
|
|
{ |
204
|
|
|
for ($i = 0; $i < $params['count']; $i++) { |
205
|
|
|
unset($this->tree[$i]); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths