Skip to content

Commit 8859d2e

Browse files
Merge pull request #38
[4.x] Remove withoutData method Closes #35
2 parents 81506fa + bd6ebe4 commit 8859d2e

7 files changed

Lines changed: 13 additions & 67 deletions

File tree

README.md

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda
2424
```json
2525
{
2626
"require-dev": {
27-
"dragon-code/benchmark": "^3.0"
27+
"dragon-code/benchmark": "^4.0"
2828
}
2929
}
3030
```
@@ -136,45 +136,6 @@ Benchmark::start()
136136
);
137137
```
138138

139-
### Without Data
140-
141-
If you want to see only the summary result of the run time without detailed information for each iteration, then you can
142-
call the `withoutData` method, which will display only the
143-
summary information:
144-
145-
```php
146-
use DragonCode\Benchmark\Benchmark;
147-
148-
Benchmark::start()
149-
->withoutData()
150-
->compare([
151-
'foo' => fn () => /* some code */,
152-
'bar' => fn () => /* some code */,
153-
]);
154-
```
155-
156-
Result example:
157-
158-
```
159-
------- ------------------- -------------------
160-
# foo bar
161-
------- ------------------- -------------------
162-
min 12.02 ms - 58.4Kb 14.71 ms - 55.4Kb
163-
max 15.66 ms - 64.8Kb 15.67 ms - 57.3Kb
164-
avg 14.65 ms - 60.1Kb 15.17 ms - 56.2Kb
165-
total 73.93 ms 76.31 ms
166-
------- ------------------- -------------------
167-
Order - 1 - - 2 -
168-
------- ------------------- -------------------
169-
```
170-
171-
> Note
172-
>
173-
> If the option to display detailed information is enabled (without using the `withoutData` method) and more than 1000
174-
> iterations are requested, then the output of detailed
175-
> information will be forcibly disabled, since there will be absolutely no point in it with a significantly increasing
176-
> load on the computer.
177-
178139
### Round Precision
179140

180141
By default, the script does not round measurement results, but you can specify the number of decimal places to which

UPGRADING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Upgrading
2+
3+
## From 3 to 4
4+
5+
- Удалён метод `withoutData`

src/Benchmark.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class Benchmark
2727

2828
protected int $iterations = 100;
2929

30-
protected bool $withData = true;
31-
3230
protected ?Closure $prepare = null;
3331

3432
protected array $result = [
@@ -74,13 +72,6 @@ public function round(?int $precision): self
7472
return $this;
7573
}
7674

77-
public function withoutData(): self
78-
{
79-
$this->withData = false;
80-
81-
return $this;
82-
}
83-
8475
public function compare(array|callable ...$callbacks): void
8576
{
8677
$values = is_array($callbacks[0]) ? $callbacks[0] : func_get_args();
@@ -155,17 +146,10 @@ protected function push(mixed $name, int $iteration, float $time, float $ram): v
155146

156147
protected function show(): void
157148
{
158-
$table = $this->withData() ? $this->transformer->forTime($this->result['each']) : [];
159-
160149
$stats = $this->transformer->forStats($this->result);
161150
$winner = $this->transformer->forWinners($stats);
162151

163-
$this->view->table($this->transformer->merge($table, $stats, $winner));
164-
}
165-
166-
protected function withData(): bool
167-
{
168-
return $this->withData && $this->iterations <= 1000;
152+
$this->view->table($this->transformer->merge($stats, $winner));
169153
}
170154

171155
protected function validate(mixed $callback): void

tests/Benchmark/AsArrayTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testIterations(): void
2525
'bar' => fn () => $this->work(),
2626
]);
2727

28-
$this->benchmark()->iterations(500)->withoutData()->compare([
28+
$this->benchmark()->iterations(500)->compare([
2929
'foo' => fn () => $this->work(),
3030
'bar' => fn () => $this->work(),
3131
]);
@@ -35,7 +35,7 @@ public function testIterations(): void
3535

3636
public function testWithoutData(): void
3737
{
38-
$this->benchmark()->withoutData()->compare([
38+
$this->benchmark()->compare([
3939
'foo' => fn () => $this->work(),
4040
'bar' => fn () => $this->work(),
4141
]);

tests/Benchmark/AsCallbackTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testIterations(): void
2525
fn () => $this->work(),
2626
);
2727

28-
$this->benchmark()->iterations(500)->withoutData()->compare(
28+
$this->benchmark()->iterations(500)->compare(
2929
fn () => $this->work(),
3030
fn () => $this->work(),
3131
);
@@ -35,7 +35,7 @@ public function testIterations(): void
3535

3636
public function testWithoutData(): void
3737
{
38-
$this->benchmark()->withoutData()->compare(
38+
$this->benchmark()->compare(
3939
fn () => $this->work(),
4040
fn () => $this->work(),
4141
);

tests/Benchmark/FailureTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public function testAsPropertiesWithoutData(): void
5353
$this->expectException(TypeError::class);
5454
$this->expectExceptionMessage('must be of type callable|array, int given');
5555

56-
$this->benchmark()->withoutData()->compare(123);
56+
$this->benchmark()->compare(123);
5757
}
5858

5959
public function testAsArrayWithoutData(): void
6060
{
6161
$this->expectException(ValueIsNotCallableException::class);
6262
$this->expectExceptionMessage('The array value must be of type callable, integer given.');
6363

64-
$this->benchmark()->withoutData()->compare([
64+
$this->benchmark()->compare([
6565
'first' => 123,
6666
'second' => 123,
6767
]);

tests/Benchmark/PrepareTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function testCallback(): void
1414

1515
$this->benchmark()
1616
->iterations(3)
17-
->withoutData()
1817
->prepare(function () use (&$result) {
1918
$result[] = 1;
2019
})
@@ -32,7 +31,6 @@ public function testParameters(): void
3231

3332
$this->benchmark()
3433
->iterations(3)
35-
->withoutData()
3634
->prepare(function (mixed $name, int $iteration) use (&$result) {
3735
$result[] = sprintf('%s:%d', $name, $iteration);
3836
})
@@ -59,7 +57,6 @@ public function testName(): void
5957

6058
$this->benchmark()
6159
->iterations(3)
62-
->withoutData()
6360
->prepare(function (mixed $name) use (&$result) {
6461
$result[] = $name;
6562
})
@@ -84,7 +81,6 @@ public function testPrepareResult(): void
8481
{
8582
$this->benchmark()
8683
->iterations(3)
87-
->withoutData()
8884
->prepare(
8985
fn (mixed $name, int $iteration) => sprintf('%s:%d', $name, $iteration)
9086
)

0 commit comments

Comments
 (0)