diff --git a/README.md b/README.md index 6430806..07d332d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda ```json { "require-dev": { - "dragon-code/benchmark": "^3.0" + "dragon-code/benchmark": "^4.0" } } ``` @@ -136,45 +136,6 @@ Benchmark::start() ); ``` -### Without Data - -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 -summary information: - -```php -use DragonCode\Benchmark\Benchmark; - -Benchmark::start() - ->withoutData() - ->compare([ - 'foo' => fn () => /* some code */, - 'bar' => fn () => /* some code */, - ]); -``` - -Result example: - -``` - ------- ------------------- ------------------- - # foo bar - ------- ------------------- ------------------- - min 12.02 ms - 58.4Kb 14.71 ms - 55.4Kb - max 15.66 ms - 64.8Kb 15.67 ms - 57.3Kb - avg 14.65 ms - 60.1Kb 15.17 ms - 56.2Kb - total 73.93 ms 76.31 ms - ------- ------------------- ------------------- - Order - 1 - - 2 - - ------- ------------------- ------------------- -``` - -> Note -> -> 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 -> information will be forcibly disabled, since there will be absolutely no point in it with a significantly increasing -> load on the computer. - ### Round Precision By default, the script does not round measurement results, but you can specify the number of decimal places to which diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..0d4b11b --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,5 @@ +# Upgrading + +## From 3 to 4 + +- Удалён метод `withoutData` diff --git a/src/Benchmark.php b/src/Benchmark.php index f2d3713..438dce4 100644 --- a/src/Benchmark.php +++ b/src/Benchmark.php @@ -27,8 +27,6 @@ class Benchmark protected int $iterations = 100; - protected bool $withData = true; - protected ?Closure $prepare = null; protected array $result = [ @@ -74,13 +72,6 @@ public function round(?int $precision): self return $this; } - public function withoutData(): self - { - $this->withData = false; - - return $this; - } - public function compare(array|callable ...$callbacks): void { $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 protected function show(): void { - $table = $this->withData() ? $this->transformer->forTime($this->result['each']) : []; - $stats = $this->transformer->forStats($this->result); $winner = $this->transformer->forWinners($stats); - $this->view->table($this->transformer->merge($table, $stats, $winner)); - } - - protected function withData(): bool - { - return $this->withData && $this->iterations <= 1000; + $this->view->table($this->transformer->merge($stats, $winner)); } protected function validate(mixed $callback): void diff --git a/tests/Benchmark/AsArrayTest.php b/tests/Benchmark/AsArrayTest.php index 35f4b4a..100dc7d 100644 --- a/tests/Benchmark/AsArrayTest.php +++ b/tests/Benchmark/AsArrayTest.php @@ -25,7 +25,7 @@ public function testIterations(): void 'bar' => fn () => $this->work(), ]); - $this->benchmark()->iterations(500)->withoutData()->compare([ + $this->benchmark()->iterations(500)->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); @@ -35,7 +35,7 @@ public function testIterations(): void public function testWithoutData(): void { - $this->benchmark()->withoutData()->compare([ + $this->benchmark()->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); diff --git a/tests/Benchmark/AsCallbackTest.php b/tests/Benchmark/AsCallbackTest.php index f0cd527..6ecffcc 100644 --- a/tests/Benchmark/AsCallbackTest.php +++ b/tests/Benchmark/AsCallbackTest.php @@ -25,7 +25,7 @@ public function testIterations(): void fn () => $this->work(), ); - $this->benchmark()->iterations(500)->withoutData()->compare( + $this->benchmark()->iterations(500)->compare( fn () => $this->work(), fn () => $this->work(), ); @@ -35,7 +35,7 @@ public function testIterations(): void public function testWithoutData(): void { - $this->benchmark()->withoutData()->compare( + $this->benchmark()->compare( fn () => $this->work(), fn () => $this->work(), ); diff --git a/tests/Benchmark/FailureTest.php b/tests/Benchmark/FailureTest.php index 80566cf..51e62d1 100644 --- a/tests/Benchmark/FailureTest.php +++ b/tests/Benchmark/FailureTest.php @@ -53,7 +53,7 @@ public function testAsPropertiesWithoutData(): void $this->expectException(TypeError::class); $this->expectExceptionMessage('must be of type callable|array, int given'); - $this->benchmark()->withoutData()->compare(123); + $this->benchmark()->compare(123); } public function testAsArrayWithoutData(): void @@ -61,7 +61,7 @@ public function testAsArrayWithoutData(): void $this->expectException(ValueIsNotCallableException::class); $this->expectExceptionMessage('The array value must be of type callable, integer given.'); - $this->benchmark()->withoutData()->compare([ + $this->benchmark()->compare([ 'first' => 123, 'second' => 123, ]); diff --git a/tests/Benchmark/PrepareTest.php b/tests/Benchmark/PrepareTest.php index 9aa504f..ba869c4 100644 --- a/tests/Benchmark/PrepareTest.php +++ b/tests/Benchmark/PrepareTest.php @@ -14,7 +14,6 @@ public function testCallback(): void $this->benchmark() ->iterations(3) - ->withoutData() ->prepare(function () use (&$result) { $result[] = 1; }) @@ -32,7 +31,6 @@ public function testParameters(): void $this->benchmark() ->iterations(3) - ->withoutData() ->prepare(function (mixed $name, int $iteration) use (&$result) { $result[] = sprintf('%s:%d', $name, $iteration); }) @@ -59,7 +57,6 @@ public function testName(): void $this->benchmark() ->iterations(3) - ->withoutData() ->prepare(function (mixed $name) use (&$result) { $result[] = $name; }) @@ -84,7 +81,6 @@ public function testPrepareResult(): void { $this->benchmark() ->iterations(3) - ->withoutData() ->prepare( fn (mixed $name, int $iteration) => sprintf('%s:%d', $name, $iteration) )