Skip to content

Commit 35b2cc2

Browse files
[4.x] Update time and memory thresholds, rename services for consistency
- Increase time thresholds in assertion tests (`100` -> `1000`, `1000` -> `10000`) and update related exception messages - Adjust memory thresholds (`100` -> `10000`) in tests and snapshots to reflect higher benchmarks - Rename `ArrService` to `ArrayService` for naming consistency - Refactor `filter` logic to delegate to `MeasurementErrorService` - Enhance sort logic in `MeasurementErrorService` with numeric sorting using `asort` - Update snapshots for `RoundTest`, `ToConsoleTest`, and other affected tests
1 parent edb0eb2 commit 35b2cc2

17 files changed

Lines changed: 118 additions & 105 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use function is_array;
1515
use function usort;
1616

17-
class ArrService
17+
class ArrayService
1818
{
1919
public function get(array $data, string $key): mixed
2020
{

src/Services/MeasurementErrorService.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace DragonCode\Benchmark\Services;
66

77
use function array_slice;
8+
use function asort;
89
use function count;
910

1011
class MeasurementErrorService
@@ -13,20 +14,25 @@ class MeasurementErrorService
1314

1415
protected int $minCount = 10;
1516

16-
public function __construct(
17-
protected ArrService $arr = new ArrService
18-
) {}
19-
2017
public function filter(array $data): array
2118
{
2219
$count = $this->count($data);
2320

24-
return $this->disabled($count) ? $data : $this->partial($data, $count);
21+
if ($this->disabled($count)) {
22+
return $data;
23+
}
24+
25+
return $this->partial($data, $count);
2526
}
2627

2728
protected function partial(array $data, int $count): array
2829
{
29-
return array_slice($this->sort($data), $this->take($count), $this->offset($count));
30+
return array_slice(
31+
array : $this->sort($data),
32+
offset : $this->offset($count),
33+
length : $this->take($count),
34+
preserve_keys: true
35+
);
3036
}
3137

3238
protected function offset(int $count): int
@@ -46,11 +52,13 @@ protected function count(array $values): int
4652

4753
protected function disabled(int $count): bool
4854
{
49-
return $count <= $this->minCount;
55+
return $count < $this->minCount;
5056
}
5157

5258
protected function sort(array $values): array
5359
{
54-
return $this->arr->sort($values);
60+
asort($values, SORT_NUMERIC);
61+
62+
return $values;
5563
}
5664
}

src/Services/ResultService.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use function array_column;
1111
use function array_map;
12-
use function array_slice;
1312
use function array_sum;
1413
use function count;
1514
use function max;
@@ -19,6 +18,10 @@ class ResultService
1918
{
2019
protected ?array $data = null;
2120

21+
public function __construct(
22+
protected MeasurementErrorService $measurement = new MeasurementErrorService,
23+
) {}
24+
2225
/**
2326
* @return \DragonCode\Benchmark\Data\ResultData[]
2427
*/
@@ -100,18 +103,6 @@ protected function metric(float $time, float $memory): MetricData
100103

101104
protected function filter(array $values): array
102105
{
103-
$count = count($values);
104-
105-
if ($count < 10) {
106-
return $values;
107-
}
108-
109-
$skip = (int) ($count * 0.1);
110-
111-
return array_slice(
112-
array : $values,
113-
offset: $skip + 1,
114-
length: $count - ($skip - 1) * 2
115-
);
106+
return $this->measurement->filter($values);
116107
}
117108
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
+-------+----------------------------+--------------------------+
2-
| # | 0 | 1 |
3-
+-------+----------------------------+--------------------------+
4-
| min | 4.56789012 ms - 50 bytes | 1.23456789 ms - 20 bytes |
5-
| max | 6.78901234 ms - 70 bytes | 3.45678901 ms - 40 bytes |
6-
| avg | 5.67860123 ms - 60 bytes | 2.3456786 ms - 30 bytes |
7-
| total | 17.03580369 ms - 182 bytes | 7.0370358 ms - 90 bytes |
8-
+-------+----------------------------+--------------------------+
9-
| order | 2 | 1 |
10-
+-------+----------------------------+--------------------------+
1+
+-------+-------------------------------+------------------------------+
2+
| # | 0 | 1 |
3+
+-------+-------------------------------+------------------------------+
4+
| min | 15.67890123 ms - 202 bytes | 2.3456789 ms - 102 bytes |
5+
| max | 112.78901234 ms - 209 bytes | 9.75678901 ms - 109 bytes |
6+
| avg | 53.02524845125 ms - 205 bytes | 5.94290024625 ms - 105 bytes |
7+
| total | 424.20198761 ms - 1.61 KB | 47.54320197 ms - 844 bytes |
8+
+-------+-------------------------------+------------------------------+
9+
| order | 2 | 1 |
10+
+-------+-------------------------------+------------------------------+
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
+-------+----------------------------+--------------------------+
2-
| # | 0 | 1 |
3-
+-------+----------------------------+--------------------------+
4-
| min | 4.56789012 ms - 50 bytes | 1.23456789 ms - 20 bytes |
5-
| max | 6.78901234 ms - 70 bytes | 3.45678901 ms - 40 bytes |
6-
| avg | 5.67860123 ms - 60 bytes | 2.3456786 ms - 30 bytes |
7-
| total | 17.03580369 ms - 182 bytes | 7.0370358 ms - 90 bytes |
8-
+-------+----------------------------+--------------------------+
9-
| order | 2 | 1 |
10-
+-------+----------------------------+--------------------------+
1+
+-------+-------------------------------+------------------------------+
2+
| # | 0 | 1 |
3+
+-------+-------------------------------+------------------------------+
4+
| min | 15.67890123 ms - 202 bytes | 2.3456789 ms - 102 bytes |
5+
| max | 112.78901234 ms - 209 bytes | 9.75678901 ms - 109 bytes |
6+
| avg | 53.02524845125 ms - 205 bytes | 5.94290024625 ms - 105 bytes |
7+
| total | 424.20198761 ms - 1.61 KB | 47.54320197 ms - 844 bytes |
8+
+-------+-------------------------------+------------------------------+
9+
| order | 2 | 1 |
10+
+-------+-------------------------------+------------------------------+
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
+-------+-------------------+-----------------+
2-
| # | 0 | 1 |
3-
+-------+-------------------+-----------------+
4-
| min | 5 ms - 50 bytes | 1 ms - 20 bytes |
5-
| max | 7 ms - 70 bytes | 3 ms - 40 bytes |
6-
| avg | 6 ms - 60 bytes | 2 ms - 30 bytes |
7-
| total | 17 ms - 182 bytes | 7 ms - 90 bytes |
8-
+-------+-------------------+-----------------+
9-
| order | 2 | 1 |
10-
+-------+-------------------+-----------------+
1+
+-------+--------------------+-------------------+
2+
| # | 0 | 1 |
3+
+-------+--------------------+-------------------+
4+
| min | 16 ms - 202 bytes | 2 ms - 102 bytes |
5+
| max | 113 ms - 209 bytes | 10 ms - 109 bytes |
6+
| avg | 53 ms - 205 bytes | 6 ms - 105 bytes |
7+
| total | 424 ms - 1.61 KB | 48 ms - 844 bytes |
8+
+-------+--------------------+-------------------+
9+
| order | 2 | 1 |
10+
+-------+--------------------+-------------------+
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
+-------+----------------------+--------------------+
2-
| # | 0 | 1 |
3-
+-------+----------------------+--------------------+
4-
| min | 4.57 ms - 50 bytes | 1.23 ms - 20 bytes |
5-
| max | 6.79 ms - 70 bytes | 3.46 ms - 40 bytes |
6-
| avg | 5.68 ms - 60 bytes | 2.35 ms - 30 bytes |
7-
| total | 17.04 ms - 182 bytes | 7.04 ms - 90 bytes |
8-
+-------+----------------------+--------------------+
9-
| order | 2 | 1 |
10-
+-------+----------------------+--------------------+
1+
+-------+-----------------------+----------------------+
2+
| # | 0 | 1 |
3+
+-------+-----------------------+----------------------+
4+
| min | 15.68 ms - 202 bytes | 2.35 ms - 102 bytes |
5+
| max | 112.79 ms - 209 bytes | 9.76 ms - 109 bytes |
6+
| avg | 53.03 ms - 205 bytes | 5.94 ms - 105 bytes |
7+
| total | 424.2 ms - 1.61 KB | 47.54 ms - 844 bytes |
8+
+-------+-----------------------+----------------------+
9+
| order | 2 | 1 |
10+
+-------+-----------------------+----------------------+
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
+-------+------------------------+-----------------------+
2-
| # | 0 | 1 |
3-
+-------+------------------------+-----------------------+
4-
| min | 4.56789 ms - 50 bytes | 1.23457 ms - 20 bytes |
5-
| max | 6.78901 ms - 70 bytes | 3.45679 ms - 40 bytes |
6-
| avg | 5.6786 ms - 60 bytes | 2.34568 ms - 30 bytes |
7-
| total | 17.0358 ms - 182 bytes | 7.03704 ms - 90 bytes |
8-
+-------+------------------------+-----------------------+
9-
| order | 2 | 1 |
10-
+-------+------------------------+-----------------------+
1+
+-------+--------------------------+------------------------+
2+
| # | 0 | 1 |
3+
+-------+--------------------------+------------------------+
4+
| min | 15.6789 ms - 202 bytes | 2.34568 ms - 102 bytes |
5+
| max | 112.78901 ms - 209 bytes | 9.75679 ms - 109 bytes |
6+
| avg | 53.02525 ms - 205 bytes | 5.9429 ms - 105 bytes |
7+
| total | 424.20199 ms - 1.61 KB | 47.5432 ms - 844 bytes |
8+
+-------+--------------------------+------------------------+
9+
| order | 2 | 1 |
10+
+-------+--------------------------+------------------------+

tests/Fixtures/CollectorFixture.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ public function all(): array
1212
{
1313
return [
1414
[
15-
[4.56789012, 50.67890],
16-
[5.67890123, 60.78901],
17-
[6.78901234, 70.89012],
15+
[14.56789012, 201],
16+
[15.67890123, 202],
17+
[16.78901234, 203],
18+
[17.78901234, 204],
19+
[18.78901234, 205],
20+
[19.78901234, 206],
21+
[110.78901234, 207],
22+
[111.78901234, 208],
23+
[112.78901234, 209],
24+
[113.78901234, 210],
1825
],
1926
[
20-
[1.23456789, 20.12345],
21-
[2.34567890, 30.23456],
22-
[3.45678901, 40.34567],
27+
[1.23456789, 101],
28+
[2.34567890, 102],
29+
[3.15678901, 103],
30+
[4.25678901, 104],
31+
[5.35678901, 105],
32+
[6.45678901, 106],
33+
[7.55678901, 107],
34+
[8.65678901, 108],
35+
[9.75678901, 109],
36+
[10.85678901, 110],
2337
],
2438
];
2539
}

tests/Unit/Assertions/ToBeAvgMemoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
test('success', function () {
66
benchmark()
77
->assert()
8-
->toBeAvgMemory(1, 100);
8+
->toBeAvgMemory(1, 10000);
99

1010
expect(true)->toBeTrue();
1111
});
@@ -21,8 +21,8 @@
2121
test('failure less than', function () {
2222
benchmark()
2323
->assert()
24-
->toBeAvgMemory(from: 100);
25-
})->throws(AssertionError::class, 'The average memory value must be greater than or equal to 100.');
24+
->toBeAvgMemory(from: 10000);
25+
})->throws(AssertionError::class, 'The average memory value must be greater than or equal to 10000.');
2626

2727
test('failure greater than', function () {
2828
benchmark()

0 commit comments

Comments
 (0)