Skip to content

Commit 19a58b5

Browse files
committed
:octocat: benchmark fix
1 parent 8d22cd3 commit 19a58b5

File tree

10 files changed

+37
-28
lines changed

10 files changed

+37
-28
lines changed

.phan/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// that functions removed in php 7.0 exist.
1414
// (See `backward_compatibility_checks` for additional options)
1515
'target_php_version' => null,
16-
'minimum_target_php_version' => '8.2',
16+
'minimum_target_php_version' => '8.4',
1717

1818
// A list of directories that should be parsed for class and
1919
// method information. After excluding the directories
@@ -23,6 +23,7 @@
2323
// Thus, both first-party and third-party code being used by
2424
// your application should be included in this list.
2525
'directory_list' => [
26+
'benchmark',
2627
'examples',
2728
'src',
2829
'tests',

benchmark/BenchmarkAbstract.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
abstract class BenchmarkAbstract{
3030
use QRMaxLengthTrait;
3131

32-
protected const BUILDDIR = __DIR__.'/../.build/phpbench/';
33-
protected const ECC_LEVELS = [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H];
34-
protected const DATAMODES = Mode::INTERFACES;
32+
protected const string BUILDDIR = __DIR__.'/../.build/phpbench/';
33+
protected const array ECC_LEVELS = [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H];
34+
protected const array DATAMODES = Mode::INTERFACES;
3535

3636
/** @var array<int, string> */
3737
protected array $dataModeData;
@@ -104,7 +104,7 @@ protected function initQROptions(array $options):void{
104104
* Initializes a QRMatrix instance and assigns it to its temp property
105105
*/
106106
public function initMatrix():void{
107-
$this->matrix = (new QRCode($this->options))
107+
$this->matrix = new QRCode($this->options)
108108
->addByteSegment($this->testData)
109109
->getQRMatrix()
110110
;

benchmark/DecoderBenchmark.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
final class DecoderBenchmark extends BenchmarkAbstract{
2626

27-
protected const DATAMODES = [Mode::BYTE => Byte::class];
27+
protected const array DATAMODES = [Mode::BYTE => Byte::class];
2828

2929
private string $imageBlob;
3030
private DecoderResult $result;
@@ -43,7 +43,7 @@ public function initOptions():void{
4343
}
4444

4545
public function generateImageBlob():void{
46-
$this->imageBlob = (new QRGdImagePNG($this->options, $this->matrix))->dump();
46+
$this->imageBlob = new QRGdImagePNG($this->options, $this->matrix)->dump();
4747
}
4848

4949
public function checkReaderResult():void{
@@ -64,7 +64,7 @@ public function GDLuminanceSource():void{
6464
// but we don't want the performance test to yell about it
6565
// @see QRCodeReaderTestAbstract::testReadData()
6666
try{
67-
$this->result = (new Decoder($this->options))
67+
$this->result = new Decoder($this->options)
6868
->decode(GDLuminanceSource::fromBlob($this->imageBlob, $this->options));
6969
}
7070
catch(QRCodeException){
@@ -82,7 +82,7 @@ public function IMagickLuminanceSource():void{
8282
$this->options->readerUseImagickIfAvailable = true;
8383

8484
try{
85-
$this->result = (new Decoder($this->options))
85+
$this->result = new Decoder($this->options)
8686
->decode(IMagickLuminanceSource::fromBlob($this->imageBlob, $this->options));
8787
}
8888
catch(QRCodeException){

benchmark/MaskPatternBenchmark.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
final class MaskPatternBenchmark extends BenchmarkAbstract{
2323

24-
protected const DATAMODES = [Mode::BYTE => Byte::class];
24+
protected const array DATAMODES = [Mode::BYTE => Byte::class];
2525

2626
public function versionProvider():Generator{
2727
for($v = 1; $v <= 40; $v++){

benchmark/OutputBenchmark.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initMatrix'])]
2525
final class OutputBenchmark extends BenchmarkAbstract{
2626

27-
protected const DATAMODES = [Mode::BYTE => Byte::class];
27+
protected const array DATAMODES = [Mode::BYTE => Byte::class];
2828

2929
public function initOptions():void{
3030

@@ -42,55 +42,55 @@ public function initOptions():void{
4242

4343
#[Subject]
4444
public function QREps():void{
45-
(new QREps($this->options, $this->matrix))->dump();
45+
new QREps($this->options, $this->matrix)->dump();
4646
}
4747

4848
#[Subject]
4949
public function QRFpdf():void{
50-
(new QRFpdf($this->options, $this->matrix))->dump();
50+
new QRFpdf($this->options, $this->matrix)->dump();
5151
}
5252

5353
/**
5454
* for some reason imageavif() is extremely slow, ~50x slower than imagepng()
5555
*/
5656
# #[Subject]
5757
# public function QRGdImageAVIF():void{
58-
# (new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix))->dump();
58+
# new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix)->dump();
5959
# }
6060

6161
#[Subject]
6262
public function QRGdImageJPEG():void{
63-
(new QRGdImageJPEG($this->options, $this->matrix))->dump();
63+
new QRGdImageJPEG($this->options, $this->matrix)->dump();
6464
}
6565

6666
#[Subject]
6767
public function QRGdImagePNG():void{
68-
(new QRGdImagePNG($this->options, $this->matrix))->dump();
68+
new QRGdImagePNG($this->options, $this->matrix)->dump();
6969
}
7070

7171
#[Subject]
7272
public function QRGdImageWEBP():void{
73-
(new QRGdImageWEBP($this->options, $this->matrix))->dump();
73+
new QRGdImageWEBP($this->options, $this->matrix)->dump();
7474
}
7575

7676
#[Subject]
7777
public function QRImagick():void{
78-
(new QRImagick($this->options, $this->matrix))->dump();
78+
new QRImagick($this->options, $this->matrix)->dump();
7979
}
8080

8181
#[Subject]
8282
public function QRMarkupSVG():void{
83-
(new QRMarkupSVG($this->options, $this->matrix))->dump();
83+
new QRMarkupSVG($this->options, $this->matrix)->dump();
8484
}
8585

8686
#[Subject]
8787
public function QRMarkupXML():void{
88-
(new QRMarkupXML($this->options, $this->matrix))->dump();
88+
new QRMarkupXML($this->options, $this->matrix)->dump();
8989
}
9090

9191
#[Subject]
9292
public function QRStringJSON():void{
93-
(new QRStringJSON($this->options, $this->matrix))->dump();
93+
new QRStringJSON($this->options, $this->matrix)->dump();
9494
}
9595

9696
}

benchmark/QRCodeBenchmark.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Tests the overall performance of the QRCode class
1919
*/
20-
final class QRCodeBenchmark extends BenchmarkAbstract{
20+
abstract class QRCodeBenchmark extends BenchmarkAbstract{
2121

2222
public function initOptions():void{
2323

@@ -32,7 +32,7 @@ public function initOptions():void{
3232
#[Subject]
3333
#[BeforeMethods(['assignParams', 'generateTestData', 'initOptions'])]
3434
public function render():void{
35-
(new QRCode($this->options))->addSegment(new $this->modeFQCN($this->testData))->render();
35+
new QRCode($this->options)->addSegment(new $this->modeFQCN($this->testData))->render();
3636
}
3737

3838
}

benchmark/QRDataBenchmark.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
use chillerlan\QRCode\Common\BitBuffer;
1515
use chillerlan\QRCode\Data\QRData;
1616
use PhpBench\Attributes\{BeforeMethods, Subject};
17+
use chillerlan\QRCode\Data\QRDataModeInterface;
1718

1819
/**
1920
* Tests the QRMatrix write performance
2021
*/
2122
final class QRDataBenchmark extends BenchmarkAbstract{
2223

23-
private QRData $qrData;
24-
private BitBuffer $bitBuffer;
24+
private QRData $qrData;
25+
private BitBuffer $bitBuffer;
26+
private QRDataModeInterface $dataMode;
2527

2628
public function initOptions():void{
2729

@@ -34,7 +36,8 @@ public function initOptions():void{
3436
}
3537

3638
public function initQRData():void{
37-
$this->qrData = new QRData($this->options, [new $this->modeFQCN($this->testData)]);
39+
$this->dataMode = new $this->modeFQCN($this->testData);
40+
$this->qrData = new QRData($this->options, [$this->dataMode]);
3841
}
3942

4043
public function initBitBuffer():void{
@@ -68,8 +71,7 @@ public function writeMatrix():void{
6871
#[Subject]
6972
#[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initQRData', 'initBitBuffer'])]
7073
public function decodeSegment():void{
71-
/** @noinspection PhpUndefinedMethodInspection */
72-
$this->modeFQCN::decodeSegment(clone $this->bitBuffer, $this->version->getVersionNumber());
74+
$this->dataMode->decodeSegment(clone $this->bitBuffer, $this->version->getVersionNumber());
7375
}
7476

7577
}

benchmark/generate-html.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @author smiley <smiley@chillerlan.net>
77
* @copyright 2024 smiley
88
* @license MIT
9+
*
10+
* @phan-file-suppress PhanTypeArraySuspiciousNullable
911
*/
1012
declare(strict_types=1);
1113

benchmark/generate-markdown.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @author smiley <smiley@chillerlan.net>
77
* @copyright 2024 smiley
88
* @license MIT
9+
*
10+
* @phan-file-suppress PhanTypeArraySuspiciousNullable
911
*/
1012
declare(strict_types=1);
1113

benchmark/parse-common.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @author smiley <smiley@chillerlan.net>
55
* @copyright 2024 smiley
66
* @license MIT
7+
*
8+
* @phan-file-suppress PhanTypeMismatchDimFetch
79
*/
810
declare(strict_types=1);
911

0 commit comments

Comments
 (0)