diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml new file mode 100644 index 0000000..cdd6b5f --- /dev/null +++ b/.github/workflows/bechmark.yml @@ -0,0 +1,34 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + - 'tests/**' + + push: + branches: ['master'] + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + - 'tests/**' + +name: bechmark + +jobs: + phpbench: + uses: yiisoft/actions/.github/workflows/phpbench.yml@master + with: + os: >- + ['ubuntu-latest', 'windows-latest'] + php: >- + ['8.1', '8.2', '8.3', '8.4'] diff --git a/composer.json b/composer.json index 428f884..33147f7 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "require-dev": { "infection/infection": "^0.27.8||^0.29.0", "maglnet/composer-require-checker": "^4.4", + "phpbench/phpbench": "^1.4", "phpunit/phpunit": "^9.5", "rector/rector": "^2.0.15", "roave/infection-static-analysis-plugin": "^1.16", diff --git a/phpbench.json b/phpbench.json new file mode 100644 index 0000000..0443602 --- /dev/null +++ b/phpbench.json @@ -0,0 +1,8 @@ +{ + "$schema":"./vendor/phpbench/phpbench/phpbench.schema.json", + "runner.bootstrap": "vendor/autoload.php", + "runner.path": "tests/Benchmark", + "runner.revs": 100000, + "runner.iterations": 5, + "runner.warmup": 5 +} diff --git a/tests/Benchmark/QueueBench.php b/tests/Benchmark/QueueBench.php new file mode 100644 index 0000000..f5976d4 --- /dev/null +++ b/tests/Benchmark/QueueBench.php @@ -0,0 +1,99 @@ +adapter = $adapter; + } + + /** + * How fast we can push 1 message + */ + #[Iterations(5)] + #[Revs(self::CONSUME_MESSAGE_COUNT)] + #[BeforeMethods('cleanupQueue')] + #[AfterMethods('cleanupQueue')] + #[OutputMode('throughput')] + #[OutputTimeUnit('seconds')] + public function benchPush(): void + { + $this->adapter->push(new Message('test', ['payload' => 'test'])); + } + + /** + * How fast we can push 100 messages + */ + #[Iterations(5)] + #[Revs(100)] + #[BeforeMethods('cleanupQueue')] + #[AfterMethods('cleanupQueue')] + #[OutputMode('throughput')] + #[OutputTimeUnit('seconds')] + public function benchPushBatch(): void + { + $message = new Message('test', ['payload' => 'test']); + for ($i = 0; $i < 100; $i++) { + $this->adapter->push($message); + } + } + + /** + * How fast we can consume 100_000 messages + */ + #[Iterations(5)] + #[Revs(1)] + #[BeforeMethods('cleanupQueue')] + #[BeforeMethods('pushMessagesForConsume')] + public function benchConsume(): void + { + $this->adapter->runExisting(static fn (): bool => true); + } + + public function pushMessagesForConsume(): void + { + for ($i = 0; $i < self::CONSUME_MESSAGE_COUNT; $i++) { + $this->adapter->push(new Message('test', ['payload' => 'test'])); + } + } + + public function cleanupQueue(): void + { + $this->adapter->runExisting(static fn (): bool => true); + } +}