diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index b090ff7..c080679 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -14,11 +14,11 @@ body: attributes: label: Environment description: | - Tip: Use the `composer info dragon-code/runtime-comparison` command to get information for Laravel Lang. + Tip: Use the `composer info dragon-code/benchmark` command to get information for Laravel Lang. Tip: Use the `php -v` command to get information for PHP. value: | - PHP Version: - - Runtime Comparison Version: + - Benchmark Version: validations: required: true diff --git a/README.md b/README.md index 9d12922..9829f28 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Runtime Comparison +# Benchmark -![the dragon code runtime comparison](https://preview.dragon-code.pro/the-dragon-code/runtime-comparison.svg?brand=php) +![the dragon code benchmark](https://preview.dragon-code.pro/the-dragon-code/benchmark.svg?brand=php) [![Stable Version][badge_stable]][link_packagist] [![Unstable Version][badge_unstable]][link_packagist] @@ -10,10 +10,10 @@ ## Installation -To get the latest version of `Runtime Comparison`, simply require the project using [Composer](https://getcomposer.org): +To get the latest version of `The Dragon Code: Benchmark`, simply require the project using [Composer](https://getcomposer.org): ```bash -composer require dragon-code/runtime-comparison --dev +composer require dragon-code/benchmark --dev ``` Or manually update `require-dev` block of `composer.json` and run `composer update` console command: @@ -21,7 +21,7 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda ```json { "require-dev": { - "dragon-code/runtime-comparison": "^1.0" + "dragon-code/benchmark": "^1.0" } } ``` @@ -33,19 +33,19 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda > The result of the execution is printed to the console, so make sure you call the code from the console. ```php -use DragonCode\RuntimeComparison\Comparator; +use DragonCode\Benchmark\Benchmark; -(new Comparator())->compare( +(new Benchmark())->compare( fn () => /* some code */, fn () => /* some code */, ); -(new Comparator())->compare([ +(new Benchmark())->compare([ fn () => /* some code */, fn () => /* some code */, ]); -(new Comparator())->compare([ +(new Benchmark())->compare([ 'foo' => fn () => /* some code */, 'bar' => fn () => /* some code */, ]); @@ -82,12 +82,12 @@ When measuring the average value among the results, when more than 10 iterations ### Iterations Count -By default, the comparator performs 100 iterations per callback, but you can change this number by calling the `iterations` method: +By default, the benchmark performs 100 iterations per callback, but you can change this number by calling the `iterations` method: ```php -use DragonCode\RuntimeComparison\Comparator; +use DragonCode\Benchmark\Benchmark; -(new Comparator()) +(new Benchmark()) ->iterations(5) ->compare( fn () => /* some code */, @@ -103,9 +103,9 @@ If you want to see only the summary result of the run time without detailed info summary information: ```php -use DragonCode\RuntimeComparison\Comparator; +use DragonCode\Benchmark\Benchmark; -(new Comparator()) +(new Benchmark()) ->withoutData() ->compare([ 'foo' => fn () => /* some code */, @@ -139,9 +139,9 @@ By default, the script does not round measurement results, but you can specify t For example: ```php -use DragonCode\RuntimeComparison\Comparator; +use DragonCode\Benchmark\Benchmark; -(new Comparator()) +(new Benchmark()) ->iterations(5) ->round(2) ->compare( @@ -175,18 +175,18 @@ Result example: This package is licensed under the [MIT License](LICENSE). -[badge_build]: https://img.shields.io/github/actions/workflow/status/TheDragonCode/runtime-comparison/phpunit.yml?style=flat-square +[badge_build]: https://img.shields.io/github/actions/workflow/status/TheDragonCode/benchmark/phpunit.yml?style=flat-square -[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/runtime-comparison.svg?style=flat-square +[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/benchmark.svg?style=flat-square -[badge_license]: https://img.shields.io/packagist/l/dragon-code/runtime-comparison.svg?style=flat-square +[badge_license]: https://img.shields.io/packagist/l/dragon-code/benchmark.svg?style=flat-square -[badge_stable]: https://img.shields.io/github/v/release/TheDragonCode/runtime-comparison?label=stable&style=flat-square +[badge_stable]: https://img.shields.io/github/v/release/TheDragonCode/benchmark?label=stable&style=flat-square [badge_unstable]: https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square -[link_build]: https://github.com/TheDragonCode/runtime-comparison/actions +[link_build]: https://github.com/TheDragonCode/benchmark/actions [link_license]: LICENSE -[link_packagist]: https://packagist.org/packages/dragon-code/runtime-comparison +[link_packagist]: https://packagist.org/packages/dragon-code/benchmark diff --git a/composer.json b/composer.json index d5d47fc..fa335d5 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,10 @@ { - "name": "dragon-code/runtime-comparison", - "description": "Simple comparison of execution time of different code", + "name": "dragon-code/benchmark", + "description": "Simple comparison of code execution speed between different options", "license": "MIT", "type": "library", "keywords": [ + "benchmark", "runtime", "comparison", "comparison-tool", @@ -22,8 +23,8 @@ } ], "support": { - "issues": "https://github.com/TheDragonCode/runtime-comparison/issues", - "source": "https://github.com/TheDragonCode/runtime-comparison" + "issues": "https://github.com/TheDragonCode/benchmark/issues", + "source": "https://github.com/TheDragonCode/benchmark" }, "funding": [ { @@ -55,7 +56,7 @@ "prefer-stable": true, "autoload": { "psr-4": { - "DragonCode\\RuntimeComparison\\": "src/" + "DragonCode\\Benchmark\\": "src/" } }, "autoload-dev": { diff --git a/src/Comparator.php b/src/Benchmark.php similarity index 90% rename from src/Comparator.php rename to src/Benchmark.php index 435ff8c..b08b05b 100644 --- a/src/Comparator.php +++ b/src/Benchmark.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison; +namespace DragonCode\Benchmark; -use DragonCode\RuntimeComparison\Exceptions\ValueIsNotCallableException; -use DragonCode\RuntimeComparison\Services\Runner; -use DragonCode\RuntimeComparison\Services\View; -use DragonCode\RuntimeComparison\Transformers\Transformer; +use DragonCode\Benchmark\Exceptions\ValueIsNotCallableException; +use DragonCode\Benchmark\Services\Runner; +use DragonCode\Benchmark\Services\View; +use DragonCode\Benchmark\Transformers\Transformer; use Symfony\Component\Console\Helper\ProgressBar as ProgressBarService; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Style\SymfonyStyle; -class Comparator +class Benchmark { protected View $view; @@ -24,7 +24,7 @@ class Comparator protected array $result = []; public function __construct( - protected Runner $runner = new Runner(), + protected Runner $runner = new Runner(), protected Transformer $transformer = new Transformer() ) { $this->view = new View(new SymfonyStyle( diff --git a/src/Contracts/Transformer.php b/src/Contracts/Transformer.php index 6ebff81..fce0827 100644 --- a/src/Contracts/Transformer.php +++ b/src/Contracts/Transformer.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Contracts; +namespace DragonCode\Benchmark\Contracts; interface Transformer { diff --git a/src/Exceptions/ValueIsNotCallableException.php b/src/Exceptions/ValueIsNotCallableException.php index 2fe2cfe..6ef349f 100644 --- a/src/Exceptions/ValueIsNotCallableException.php +++ b/src/Exceptions/ValueIsNotCallableException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Exceptions; +namespace DragonCode\Benchmark\Exceptions; use TypeError; diff --git a/src/Services/Arr.php b/src/Services/Arr.php index 9546500..2bbfc3b 100644 --- a/src/Services/Arr.php +++ b/src/Services/Arr.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Services; +namespace DragonCode\Benchmark\Services; class Arr { diff --git a/src/Services/MeasurementError.php b/src/Services/MeasurementError.php index 00a9056..db625eb 100644 --- a/src/Services/MeasurementError.php +++ b/src/Services/MeasurementError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Services; +namespace DragonCode\Benchmark\Services; class MeasurementError { diff --git a/src/Services/Runner.php b/src/Services/Runner.php index 4f5134e..a3627ba 100644 --- a/src/Services/Runner.php +++ b/src/Services/Runner.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Services; +namespace DragonCode\Benchmark\Services; class Runner { diff --git a/src/Services/View.php b/src/Services/View.php index 1cfb889..cf31123 100644 --- a/src/Services/View.php +++ b/src/Services/View.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Services; +namespace DragonCode\Benchmark\Services; -use DragonCode\RuntimeComparison\View\ProgressBar; -use DragonCode\RuntimeComparison\View\Table; +use DragonCode\Benchmark\View\ProgressBar; +use DragonCode\Benchmark\View\Table; use Symfony\Component\Console\Style\SymfonyStyle; class View diff --git a/src/Transformers/Base.php b/src/Transformers/Base.php index 10106d5..2a62b76 100644 --- a/src/Transformers/Base.php +++ b/src/Transformers/Base.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; -use DragonCode\RuntimeComparison\Contracts\Transformer as TransformerContract; +use DragonCode\Benchmark\Contracts\Transformer as TransformerContract; abstract class Base implements TransformerContract { diff --git a/src/Transformers/Separator.php b/src/Transformers/Separator.php index f61b2cd..f41dc25 100644 --- a/src/Transformers/Separator.php +++ b/src/Transformers/Separator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; use Symfony\Component\Console\Helper\TableSeparator; diff --git a/src/Transformers/Stats.php b/src/Transformers/Stats.php index 0678b2e..33cb634 100644 --- a/src/Transformers/Stats.php +++ b/src/Transformers/Stats.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; -use DragonCode\RuntimeComparison\Services\MeasurementError; +use DragonCode\Benchmark\Services\MeasurementError; class Stats extends Base { diff --git a/src/Transformers/Times.php b/src/Transformers/Times.php index 9aefd77..8199f20 100644 --- a/src/Transformers/Times.php +++ b/src/Transformers/Times.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; class Times extends Base { diff --git a/src/Transformers/Transformer.php b/src/Transformers/Transformer.php index 9faff8b..7b704f0 100644 --- a/src/Transformers/Transformer.php +++ b/src/Transformers/Transformer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; -use DragonCode\RuntimeComparison\Contracts\Transformer as TransformerContract; +use DragonCode\Benchmark\Contracts\Transformer as TransformerContract; class Transformer { diff --git a/src/Transformers/Winner.php b/src/Transformers/Winner.php index 748248b..8b38611 100644 --- a/src/Transformers/Winner.php +++ b/src/Transformers/Winner.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\Transformers; +namespace DragonCode\Benchmark\Transformers; -use DragonCode\RuntimeComparison\Services\Arr; +use DragonCode\Benchmark\Services\Arr; class Winner extends Base { diff --git a/src/View/ProgressBar.php b/src/View/ProgressBar.php index 3868545..8f30f84 100644 --- a/src/View/ProgressBar.php +++ b/src/View/ProgressBar.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\View; +namespace DragonCode\Benchmark\View; use Symfony\Component\Console\Helper\ProgressBar as ProgressBarService; use Symfony\Component\Console\Style\SymfonyStyle; diff --git a/src/View/Table.php b/src/View/Table.php index f1a2bbf..41cbdf8 100644 --- a/src/View/Table.php +++ b/src/View/Table.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DragonCode\RuntimeComparison\View; +namespace DragonCode\Benchmark\View; use Symfony\Component\Console\Style\SymfonyStyle; diff --git a/tests/Comparator/AsArrayTest.php b/tests/Benchmark/AsArrayTest.php similarity index 76% rename from tests/Comparator/AsArrayTest.php rename to tests/Benchmark/AsArrayTest.php index 6369fe8..35f4b4a 100644 --- a/tests/Comparator/AsArrayTest.php +++ b/tests/Benchmark/AsArrayTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Comparator; +namespace Tests\Benchmark; use Tests\TestCase; @@ -10,7 +10,7 @@ class AsArrayTest extends TestCase { public function testDefault(): void { - $this->comparator()->compare([ + $this->benchmark()->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); @@ -20,12 +20,12 @@ public function testDefault(): void public function testIterations(): void { - $this->comparator()->iterations(5)->compare([ + $this->benchmark()->iterations(5)->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); - $this->comparator()->iterations(500)->withoutData()->compare([ + $this->benchmark()->iterations(500)->withoutData()->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); @@ -35,7 +35,7 @@ public function testIterations(): void public function testWithoutData(): void { - $this->comparator()->withoutData()->compare([ + $this->benchmark()->withoutData()->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); @@ -45,7 +45,7 @@ public function testWithoutData(): void public function testRound(): void { - $this->comparator()->round(2)->compare([ + $this->benchmark()->round(2)->compare([ 'foo' => fn () => $this->work(), 'bar' => fn () => $this->work(), ]); diff --git a/tests/Comparator/AsCallbackTest.php b/tests/Benchmark/AsCallbackTest.php similarity index 74% rename from tests/Comparator/AsCallbackTest.php rename to tests/Benchmark/AsCallbackTest.php index 1ae1d60..dd2c91c 100644 --- a/tests/Comparator/AsCallbackTest.php +++ b/tests/Benchmark/AsCallbackTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Comparator; +namespace Tests\Benchmark; use Tests\TestCase; @@ -10,7 +10,7 @@ class AsCallbackTest extends TestCase { public function testDefault(): void { - $this->comparator()->compare( + $this->benchmark()->compare( fn () => $this->work(), fn () => $this->work(), ); @@ -20,12 +20,12 @@ public function testDefault(): void public function testIterations(): void { - $this->comparator()->iterations(5)->compare( + $this->benchmark()->iterations(5)->compare( fn () => $this->work(), fn () => $this->work(), ); - $this->comparator()->iterations(500)->withoutData()->compare( + $this->benchmark()->iterations(500)->withoutData()->compare( fn () => $this->work(), fn () => $this->work(), ); @@ -35,7 +35,7 @@ public function testIterations(): void public function testWithoutData(): void { - $this->comparator()->withoutData()->compare( + $this->benchmark()->withoutData()->compare( fn () => $this->work(), fn () => $this->work(), ); @@ -45,7 +45,7 @@ public function testWithoutData(): void public function testRound(): void { - $this->comparator()->round(2)->compare( + $this->benchmark()->round(2)->compare( fn () => $this->work(), fn () => $this->work(), ); diff --git a/tests/Comparator/FailureTest.php b/tests/Benchmark/FailureTest.php similarity index 79% rename from tests/Comparator/FailureTest.php rename to tests/Benchmark/FailureTest.php index fc30520..80566cf 100644 --- a/tests/Comparator/FailureTest.php +++ b/tests/Benchmark/FailureTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Tests\Comparator; +namespace Tests\Benchmark; -use DragonCode\RuntimeComparison\Exceptions\ValueIsNotCallableException; +use DragonCode\Benchmark\Exceptions\ValueIsNotCallableException; use Tests\TestCase; use TypeError; @@ -15,7 +15,7 @@ public function testAsProperties(): void $this->expectException(TypeError::class); $this->expectExceptionMessage('must be of type callable|array, int given'); - $this->comparator()->compare(123); + $this->benchmark()->compare(123); } public function testAsArray(): void @@ -23,7 +23,7 @@ public function testAsArray(): void $this->expectException(ValueIsNotCallableException::class); $this->expectExceptionMessage('The array value must be of type callable, integer given.'); - $this->comparator()->compare([ + $this->benchmark()->compare([ 'first' => 123, 'second' => 123, ]); @@ -34,7 +34,7 @@ public function testAsPropertiesWithIterations(): void $this->expectException(TypeError::class); $this->expectExceptionMessage('must be of type callable|array, int given'); - $this->comparator()->iterations(5)->compare(123); + $this->benchmark()->iterations(5)->compare(123); } public function testAsArrayWithIterations(): void @@ -42,7 +42,7 @@ public function testAsArrayWithIterations(): void $this->expectException(ValueIsNotCallableException::class); $this->expectExceptionMessage('The array value must be of type callable, integer given.'); - $this->comparator()->iterations(5)->compare([ + $this->benchmark()->iterations(5)->compare([ 'first' => 123, 'second' => 123, ]); @@ -53,7 +53,7 @@ public function testAsPropertiesWithoutData(): void $this->expectException(TypeError::class); $this->expectExceptionMessage('must be of type callable|array, int given'); - $this->comparator()->withoutData()->compare(123); + $this->benchmark()->withoutData()->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->comparator()->withoutData()->compare([ + $this->benchmark()->withoutData()->compare([ 'first' => 123, 'second' => 123, ]); diff --git a/tests/TestCase.php b/tests/TestCase.php index a158e1e..63129a5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,14 +4,14 @@ namespace Tests; -use DragonCode\RuntimeComparison\Comparator; +use DragonCode\Benchmark\Benchmark; use PHPUnit\Framework\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { - protected function comparator(): Comparator + protected function benchmark(): Benchmark { - return new Comparator(); + return new Benchmark(); } protected function work(): void