:octocat: benchmark fix

This commit is contained in:
smiley
2026-03-17 13:34:34 +01:00
parent 8d22cd3154
commit 19a58b52fb
10 changed files with 37 additions and 28 deletions
+2 -1
View File
@@ -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',
+4 -4
View File
@@ -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<int, string> */
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()
;
+4 -4
View File
@@ -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){
+1 -1
View File
@@ -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++){
+11 -11
View File
@@ -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();
}
}
+2 -2
View File
@@ -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();
}
}
+7 -5
View File
@@ -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());
}
}
+2
View File
@@ -6,6 +6,8 @@
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @phan-file-suppress PhanTypeArraySuspiciousNullable
*/
declare(strict_types=1);
+2
View File
@@ -6,6 +6,8 @@
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @phan-file-suppress PhanTypeArraySuspiciousNullable
*/
declare(strict_types=1);
+2
View File
@@ -4,6 +4,8 @@
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @phan-file-suppress PhanTypeMismatchDimFetch
*/
declare(strict_types=1);