You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When measuring the average value among the results, when more than 10 iterations are used, the final data is filtered by peak values. The calculation of the 10% of the lowest and
82
-
10% of the highest values is excluded from the total result, thus the final data becomes cleaner and less dependent on any external factors.
82
+
When measuring the average value among the results, when more than 10 iterations are used, the final data is filtered by
83
+
peak values. The calculation of the 10% of the lowest and
84
+
10% of the highest values is excluded from the total result, thus the final data becomes cleaner and less dependent on
85
+
any external factors.
83
86
84
87
### Iterations Count
85
88
86
-
By default, the benchmark performs 100 iterations per callback, but you can change this number by calling the `iterations` method:
89
+
By default, the benchmark performs 100 iterations per callback, but you can change this number by calling
90
+
the `iterations` method:
87
91
88
92
```php
89
93
use DragonCode\Benchmark\Benchmark;
@@ -117,9 +121,23 @@ If the passed value is less than 1, then one iteration will be performed for eac
You can also get the number of the current execution iteration from the input parameter:
125
+
126
+
```php
127
+
use DragonCode\Benchmark\Benchmark;
128
+
129
+
(new Benchmark())
130
+
->iterations(5)
131
+
->compare(
132
+
fn (int $iteration) => /* some code */,
133
+
fn (int $iteration) => /* some code */,
134
+
);
135
+
```
136
+
120
137
### Without Data
121
138
122
-
If you want to see only the summary result of the run time without detailed information for each iteration, then you can call the `withoutData` method, which will display only the
139
+
If you want to see only the summary result of the run time without detailed information for each iteration, then you can
140
+
call the `withoutData` method, which will display only the
123
141
summary information:
124
142
125
143
```php
@@ -150,12 +168,15 @@ Result example:
150
168
151
169
> Note
152
170
>
153
-
> If the option to display detailed information is enabled (without using the `withoutData` method) and more than 1000 iterations are requested, then the output of detailed
154
-
> information will be forcibly disabled, since there will be absolutely no point in it with a significantly increasing load on the computer.
171
+
> If the option to display detailed information is enabled (without using the `withoutData` method) and more than 1000
172
+
> iterations are requested, then the output of detailed
173
+
> information will be forcibly disabled, since there will be absolutely no point in it with a significantly increasing
174
+
> load on the computer.
155
175
156
176
### Round Precision
157
177
158
-
By default, the script does not round measurement results, but you can specify the number of decimal places to which rounding can be performed.
178
+
By default, the script does not round measurement results, but you can specify the number of decimal places to which
179
+
rounding can be performed.
159
180
160
181
For example:
161
182
@@ -194,7 +215,8 @@ Result example:
194
215
195
216
### Prepare Data
196
217
197
-
In some cases, it becomes necessary to call some action before starting each check cycle so that its time does not fall into the result of the runtime check.
218
+
In some cases, it becomes necessary to call some action before starting each check cycle so that its time does not fall
219
+
into the result of the runtime check.
198
220
There is a `prepare` method for this:
199
221
200
222
```php
@@ -208,7 +230,8 @@ use DragonCode\Benchmark\Benchmark;
208
230
);
209
231
```
210
232
211
-
When calling a callback, the name and iteration parameters are passed to it. If necessary, you can use this information inside the callback function.
233
+
When calling a callback, the name and iteration parameters are passed to it. If necessary, you can use this information
234
+
inside the callback function.
212
235
213
236
```php
214
237
use DragonCode\Benchmark\Benchmark;
@@ -221,6 +244,20 @@ use DragonCode\Benchmark\Benchmark;
221
244
);
222
245
```
223
246
247
+
You can also get the number of the current iteration and the result of the execution of the preliminary function from
248
+
the input parameter:
249
+
250
+
```php
251
+
use DragonCode\Benchmark\Benchmark;
252
+
253
+
(new Benchmark())
254
+
->prepare(fn (mixed $name, int $iteration) => /* some code */)
255
+
->compare(
256
+
fn (int $iteration, mixed $prepareResult) => /* some code */,
257
+
fn (int $iteration, mixed $prepareResult) => /* some code */,
258
+
);
259
+
```
260
+
224
261
## Information
225
262
226
263
```
@@ -242,13 +279,15 @@ use DragonCode\Benchmark\Benchmark;
242
279
------- ------------------ ------------------
243
280
```
244
281
245
-
*`foo`, `bar` - The names of the columns in the passed array. Needed for identification. By default, the array index is used, starting from zero. For example, `1, 2, 3,.. N+1`.
282
+
*`foo`, `bar` - The names of the columns in the passed array. Needed for identification. By default, the array index is
283
+
used, starting from zero. For example, `1, 2, 3,.. N+1`.
*`11.33 ms` - Execution time of the checked code in one iteration.
248
286
*`0b`, `6.8Kb`, etc. - The amount of RAM used by the checked code.
249
287
*`min` - Minimum code processing time.
250
288
*`max` - Maximum code processing time.
251
-
*`avg` - The arithmetic mean value among all iterations, taking into account the elimination of 10% of the smallest and 10% of the largest values to obtain a more accurate value
289
+
*`avg` - The arithmetic mean value among all iterations, taking into account the elimination of 10% of the smallest and
290
+
10% of the largest values to obtain a more accurate value
252
291
through the possible intervention of external factors.
253
292
*`total` - The total time and RAM spent on checking all iterations of the code.
0 commit comments