From 19a58b52fb036c4f16349a36f963a9361f50f982 Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 17 Mar 2026 13:34:34 +0100 Subject: [PATCH] :octocat: benchmark fix --- .phan/config.php | 3 ++- benchmark/BenchmarkAbstract.php | 8 ++++---- benchmark/DecoderBenchmark.php | 8 ++++---- benchmark/MaskPatternBenchmark.php | 2 +- benchmark/OutputBenchmark.php | 22 +++++++++++----------- benchmark/QRCodeBenchmark.php | 4 ++-- benchmark/QRDataBenchmark.php | 12 +++++++----- benchmark/generate-html.php | 2 ++ benchmark/generate-markdown.php | 2 ++ benchmark/parse-common.php | 2 ++ 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 67d77ec97..7b9817c06 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -13,7 +13,7 @@ return [ // that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) 'target_php_version' => null, - 'minimum_target_php_version' => '8.2', + 'minimum_target_php_version' => '8.4', // A list of directories that should be parsed for class and // method information. After excluding the directories @@ -23,6 +23,7 @@ return [ // Thus, both first-party and third-party code being used by // your application should be included in this list. 'directory_list' => [ + 'benchmark', 'examples', 'src', 'tests', diff --git a/benchmark/BenchmarkAbstract.php b/benchmark/BenchmarkAbstract.php index 9c28c6b24..a5b4c52b4 100644 --- a/benchmark/BenchmarkAbstract.php +++ b/benchmark/BenchmarkAbstract.php @@ -29,9 +29,9 @@ use function extension_loaded, is_dir, mb_substr, mkdir, sprintf, str_repeat, st abstract class BenchmarkAbstract{ use QRMaxLengthTrait; - protected const BUILDDIR = __DIR__.'/../.build/phpbench/'; - protected const ECC_LEVELS = [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H]; - protected const DATAMODES = Mode::INTERFACES; + protected const string BUILDDIR = __DIR__.'/../.build/phpbench/'; + protected const array ECC_LEVELS = [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H]; + protected const array DATAMODES = Mode::INTERFACES; /** @var array */ protected array $dataModeData; @@ -104,7 +104,7 @@ abstract class BenchmarkAbstract{ * Initializes a QRMatrix instance and assigns it to its temp property */ public function initMatrix():void{ - $this->matrix = (new QRCode($this->options)) + $this->matrix = new QRCode($this->options) ->addByteSegment($this->testData) ->getQRMatrix() ; diff --git a/benchmark/DecoderBenchmark.php b/benchmark/DecoderBenchmark.php index 44b74ef7d..4f8cb8edc 100644 --- a/benchmark/DecoderBenchmark.php +++ b/benchmark/DecoderBenchmark.php @@ -24,7 +24,7 @@ use RuntimeException; */ final class DecoderBenchmark extends BenchmarkAbstract{ - protected const DATAMODES = [Mode::BYTE => Byte::class]; + protected const array DATAMODES = [Mode::BYTE => Byte::class]; private string $imageBlob; private DecoderResult $result; @@ -43,7 +43,7 @@ final class DecoderBenchmark extends BenchmarkAbstract{ } public function generateImageBlob():void{ - $this->imageBlob = (new QRGdImagePNG($this->options, $this->matrix))->dump(); + $this->imageBlob = new QRGdImagePNG($this->options, $this->matrix)->dump(); } public function checkReaderResult():void{ @@ -64,7 +64,7 @@ final class DecoderBenchmark extends BenchmarkAbstract{ // but we don't want the performance test to yell about it // @see QRCodeReaderTestAbstract::testReadData() try{ - $this->result = (new Decoder($this->options)) + $this->result = new Decoder($this->options) ->decode(GDLuminanceSource::fromBlob($this->imageBlob, $this->options)); } catch(QRCodeException){ @@ -82,7 +82,7 @@ final class DecoderBenchmark extends BenchmarkAbstract{ $this->options->readerUseImagickIfAvailable = true; try{ - $this->result = (new Decoder($this->options)) + $this->result = new Decoder($this->options) ->decode(IMagickLuminanceSource::fromBlob($this->imageBlob, $this->options)); } catch(QRCodeException){ diff --git a/benchmark/MaskPatternBenchmark.php b/benchmark/MaskPatternBenchmark.php index 488ec72e7..551b59cff 100644 --- a/benchmark/MaskPatternBenchmark.php +++ b/benchmark/MaskPatternBenchmark.php @@ -21,7 +21,7 @@ use Generator; */ final class MaskPatternBenchmark extends BenchmarkAbstract{ - protected const DATAMODES = [Mode::BYTE => Byte::class]; + protected const array DATAMODES = [Mode::BYTE => Byte::class]; public function versionProvider():Generator{ for($v = 1; $v <= 40; $v++){ diff --git a/benchmark/OutputBenchmark.php b/benchmark/OutputBenchmark.php index 837678029..c2cee6eb4 100644 --- a/benchmark/OutputBenchmark.php +++ b/benchmark/OutputBenchmark.php @@ -24,7 +24,7 @@ use PhpBench\Attributes\{BeforeMethods, Subject}; #[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initMatrix'])] final class OutputBenchmark extends BenchmarkAbstract{ - protected const DATAMODES = [Mode::BYTE => Byte::class]; + protected const array DATAMODES = [Mode::BYTE => Byte::class]; public function initOptions():void{ @@ -42,12 +42,12 @@ final class OutputBenchmark extends BenchmarkAbstract{ #[Subject] public function QREps():void{ - (new QREps($this->options, $this->matrix))->dump(); + new QREps($this->options, $this->matrix)->dump(); } #[Subject] public function QRFpdf():void{ - (new QRFpdf($this->options, $this->matrix))->dump(); + new QRFpdf($this->options, $this->matrix)->dump(); } /** @@ -55,42 +55,42 @@ final class OutputBenchmark extends BenchmarkAbstract{ */ # #[Subject] # public function QRGdImageAVIF():void{ -# (new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix))->dump(); +# new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix)->dump(); # } #[Subject] public function QRGdImageJPEG():void{ - (new QRGdImageJPEG($this->options, $this->matrix))->dump(); + new QRGdImageJPEG($this->options, $this->matrix)->dump(); } #[Subject] public function QRGdImagePNG():void{ - (new QRGdImagePNG($this->options, $this->matrix))->dump(); + new QRGdImagePNG($this->options, $this->matrix)->dump(); } #[Subject] public function QRGdImageWEBP():void{ - (new QRGdImageWEBP($this->options, $this->matrix))->dump(); + new QRGdImageWEBP($this->options, $this->matrix)->dump(); } #[Subject] public function QRImagick():void{ - (new QRImagick($this->options, $this->matrix))->dump(); + new QRImagick($this->options, $this->matrix)->dump(); } #[Subject] public function QRMarkupSVG():void{ - (new QRMarkupSVG($this->options, $this->matrix))->dump(); + new QRMarkupSVG($this->options, $this->matrix)->dump(); } #[Subject] public function QRMarkupXML():void{ - (new QRMarkupXML($this->options, $this->matrix))->dump(); + new QRMarkupXML($this->options, $this->matrix)->dump(); } #[Subject] public function QRStringJSON():void{ - (new QRStringJSON($this->options, $this->matrix))->dump(); + new QRStringJSON($this->options, $this->matrix)->dump(); } } diff --git a/benchmark/QRCodeBenchmark.php b/benchmark/QRCodeBenchmark.php index 0c6936280..7c508327f 100644 --- a/benchmark/QRCodeBenchmark.php +++ b/benchmark/QRCodeBenchmark.php @@ -17,7 +17,7 @@ use PhpBench\Attributes\{BeforeMethods, Subject}; /** * Tests the overall performance of the QRCode class */ -final class QRCodeBenchmark extends BenchmarkAbstract{ +abstract class QRCodeBenchmark extends BenchmarkAbstract{ public function initOptions():void{ @@ -32,7 +32,7 @@ final class QRCodeBenchmark extends BenchmarkAbstract{ #[Subject] #[BeforeMethods(['assignParams', 'generateTestData', 'initOptions'])] public function render():void{ - (new QRCode($this->options))->addSegment(new $this->modeFQCN($this->testData))->render(); + new QRCode($this->options)->addSegment(new $this->modeFQCN($this->testData))->render(); } } diff --git a/benchmark/QRDataBenchmark.php b/benchmark/QRDataBenchmark.php index 83b4d6251..0c689972e 100644 --- a/benchmark/QRDataBenchmark.php +++ b/benchmark/QRDataBenchmark.php @@ -14,14 +14,16 @@ namespace chillerlan\QRCodeBenchmark; use chillerlan\QRCode\Common\BitBuffer; use chillerlan\QRCode\Data\QRData; use PhpBench\Attributes\{BeforeMethods, Subject}; +use chillerlan\QRCode\Data\QRDataModeInterface; /** * Tests the QRMatrix write performance */ final class QRDataBenchmark extends BenchmarkAbstract{ - private QRData $qrData; - private BitBuffer $bitBuffer; + private QRData $qrData; + private BitBuffer $bitBuffer; + private QRDataModeInterface $dataMode; public function initOptions():void{ @@ -34,7 +36,8 @@ final class QRDataBenchmark extends BenchmarkAbstract{ } public function initQRData():void{ - $this->qrData = new QRData($this->options, [new $this->modeFQCN($this->testData)]); + $this->dataMode = new $this->modeFQCN($this->testData); + $this->qrData = new QRData($this->options, [$this->dataMode]); } public function initBitBuffer():void{ @@ -68,8 +71,7 @@ final class QRDataBenchmark extends BenchmarkAbstract{ #[Subject] #[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initQRData', 'initBitBuffer'])] public function decodeSegment():void{ - /** @noinspection PhpUndefinedMethodInspection */ - $this->modeFQCN::decodeSegment(clone $this->bitBuffer, $this->version->getVersionNumber()); + $this->dataMode->decodeSegment(clone $this->bitBuffer, $this->version->getVersionNumber()); } } diff --git a/benchmark/generate-html.php b/benchmark/generate-html.php index 5477d6dce..a8cdb1741 100644 --- a/benchmark/generate-html.php +++ b/benchmark/generate-html.php @@ -6,6 +6,8 @@ * @author smiley * @copyright 2024 smiley * @license MIT + * + * @phan-file-suppress PhanTypeArraySuspiciousNullable */ declare(strict_types=1); diff --git a/benchmark/generate-markdown.php b/benchmark/generate-markdown.php index d7a4d8fef..e4c8d21a6 100644 --- a/benchmark/generate-markdown.php +++ b/benchmark/generate-markdown.php @@ -6,6 +6,8 @@ * @author smiley * @copyright 2024 smiley * @license MIT + * + * @phan-file-suppress PhanTypeArraySuspiciousNullable */ declare(strict_types=1); diff --git a/benchmark/parse-common.php b/benchmark/parse-common.php index cbb0d5428..22c9d7a90 100644 --- a/benchmark/parse-common.php +++ b/benchmark/parse-common.php @@ -4,6 +4,8 @@ * @author smiley * @copyright 2024 smiley * @license MIT + * + * @phan-file-suppress PhanTypeMismatchDimFetch */ declare(strict_types=1);