Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
## From 3 to 4

- Удалён метод `withoutData`
- Метод `prepare` переименован в `beforeEach`
12 changes: 6 additions & 6 deletions src/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Benchmark

protected int $iterations = 100;

protected ?Closure $prepare = null;
protected ?Closure $beforeEach = null;

protected array $result = [
'each' => [],
Expand All @@ -51,9 +51,9 @@ public static function start(): static
return new static();
}

public function prepare(callable $callback): self
public function beforeEach(callable $callback): self
{
$this->prepare = $callback;
$this->beforeEach = $callback;

return $this;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ protected function each(mixed $name, callable $callback, ProgressBarService $pro
protected function run(mixed $name, callable $callback, ProgressBarService $progressBar): void
{
for ($i = 1; $i <= $this->iterations; ++$i) {
$result = $this->runPrepare($name, $i);
$result = $this->runBeforeEach($name, $i);

[$time, $ram] = $this->call($callback, [$i, $result]);

Expand All @@ -124,9 +124,9 @@ protected function run(mixed $name, callable $callback, ProgressBarService $prog
}
}

protected function runPrepare(mixed $name, int $iteration): mixed
protected function runBeforeEach(mixed $name, int $iteration): mixed
{
if ($callback = $this->prepare) {
if ($callback = $this->beforeEach) {
return $callback($name, $iteration);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Benchmark/PrepareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testCallback(): void

$this->benchmark()
->iterations(3)
->prepare(function () use (&$result) {
->beforeEach(function () use (&$result) {
$result[] = 1;
})
->compare([
Expand All @@ -31,7 +31,7 @@ public function testParameters(): void

$this->benchmark()
->iterations(3)
->prepare(function (mixed $name, int $iteration) use (&$result) {
->beforeEach(function (mixed $name, int $iteration) use (&$result) {
$result[] = sprintf('%s:%d', $name, $iteration);
})
->compare([
Expand All @@ -57,7 +57,7 @@ public function testName(): void

$this->benchmark()
->iterations(3)
->prepare(function (mixed $name) use (&$result) {
->beforeEach(function (mixed $name) use (&$result) {
$result[] = $name;
})
->compare([
Expand All @@ -81,7 +81,7 @@ public function testPrepareResult(): void
{
$this->benchmark()
->iterations(3)
->prepare(
->beforeEach(
fn (mixed $name, int $iteration) => sprintf('%s:%d', $name, $iteration)
)
->compare([
Expand Down