Skip to content

Commit 9aa42ea

Browse files
committed
refactor(Bench): Remove BenchOptions DTO
1 parent de06564 commit 9aa42ea

File tree

4 files changed

+22
-36
lines changed

4 files changed

+22
-36
lines changed

src/Bench/BenchOptions.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Bench/BenchWith.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,25 @@ public function __construct(
2323
* It might be a callable or an array with class name and non-public method name.
2424
*/
2525
public readonly array $callables,
26+
27+
/**
28+
* @var array Arguments to pass to the benchmarked functions.
29+
*/
2630
public readonly array $arguments = [],
27-
public readonly BenchOptions $options = new BenchOptions(),
28-
) {}
31+
32+
/**
33+
* @var int<1, max> Number of iterations to run for each benchmark.
34+
*/
35+
public readonly int $iterations = 1000,
36+
37+
/**
38+
* @var int<1, max> Number of revolutions to run for each benchmark.
39+
* A revolution is a single execution of the benchmarked function.
40+
*/
41+
public readonly int $revolutions = 5,
42+
) {
43+
\count($callables) < 1 or throw new \InvalidArgumentException('At least one callable must be provided.');
44+
$iterations > 0 or throw new \InvalidArgumentException('Iterations must be greater than 0.');
45+
$revolutions > 0 or throw new \InvalidArgumentException('Revolutions must be greater than 0.');
46+
}
2947
}

src/Bench/Internal/BenchInvoker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __invoke(TestInfo $info): mixed
3939

4040
Benchmark::start()
4141
->withoutData()
42-
->iterations($attr->options->iterations)
42+
->iterations($attr->iterations)
4343
->compare(
4444
...$functions,
4545
);

tests/Bench/Self/BenchWithAttr.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Bench\Self;
66

7-
use Testo\Bench\BenchOptions;
87
use Testo\Bench\BenchWith;
98

109
final class BenchWithAttr
@@ -15,9 +14,7 @@ final class BenchWithAttr
1514
[self::class, 'sumSlow'],
1615
],
1716
arguments: [1, 2],
18-
options: new BenchOptions(
19-
iterations: 10_000,
20-
)
17+
iterations: 10_000,
2118
)]
2219
public static function sumFast(int $a, int $b): int
2320
{

0 commit comments

Comments
 (0)