OutputBenchmark.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Class OutputBenchmark
  4. *
  5. * @created 23.04.2024
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2024 smiley
  8. * @license MIT
  9. */
  10. declare(strict_types=1);
  11. namespace chillerlan\QRCodeBenchmark;
  12. use chillerlan\QRCode\Common\{EccLevel, Mode};
  13. use chillerlan\QRCode\Data\Byte;
  14. use chillerlan\QRCode\Output\{
  15. QREps, QRFpdf, QRGdImageJPEG, QRGdImagePNG, QRGdImageWEBP, QRImagick, QRMarkupSVG, QRStringJSON
  16. };
  17. use PhpBench\Attributes\{BeforeMethods, Subject};
  18. /**
  19. * Tests the performance of the built-in output classes
  20. */
  21. #[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initMatrix'])]
  22. final class OutputBenchmark extends BenchmarkAbstract{
  23. protected const ECC_LEVELS = [EccLevel::H];
  24. protected const DATAMODES = [Mode::BYTE => Byte::class];
  25. public function initOptions():void{
  26. $options = [
  27. 'version' => $this->version->getVersionNumber(),
  28. 'eccLevel' => $this->eccLevel->getLevel(),
  29. 'connectPaths' => true,
  30. 'drawLightModules' => true,
  31. 'drawCircularModules' => true,
  32. 'gdImageUseUpscale' => false, // set to false to allow proper comparison
  33. ];
  34. $this->initQROptions($options);
  35. }
  36. #[Subject]
  37. public function QREps():void{
  38. (new QREps($this->options, $this->matrix))->dump();
  39. }
  40. #[Subject]
  41. public function QRFpdf():void{
  42. (new QRFpdf($this->options, $this->matrix))->dump();
  43. }
  44. /**
  45. * for some reason imageavif() is extremely slow, ~50x slower than imagepng()
  46. */
  47. # #[Subject]
  48. # public function QRGdImageAVIF():void{
  49. # (new QRGdImageAVIF($this->options, $this->matrix))->dump();
  50. # }
  51. #[Subject]
  52. public function QRGdImageJPEG():void{
  53. (new QRGdImageJPEG($this->options, $this->matrix))->dump();
  54. }
  55. #[Subject]
  56. public function QRGdImagePNG():void{
  57. (new QRGdImagePNG($this->options, $this->matrix))->dump();
  58. }
  59. #[Subject]
  60. public function QRGdImageWEBP():void{
  61. (new QRGdImageWEBP($this->options, $this->matrix))->dump();
  62. }
  63. #[Subject]
  64. public function QRImagick():void{
  65. (new QRImagick($this->options, $this->matrix))->dump();
  66. }
  67. #[Subject]
  68. public function QRMarkupSVG():void{
  69. (new QRMarkupSVG($this->options, $this->matrix))->dump();
  70. }
  71. #[Subject]
  72. public function QRStringJSON():void{
  73. (new QRStringJSON($this->options, $this->matrix))->dump();
  74. }
  75. }