OutputBenchmark.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\Mode;
  13. use chillerlan\QRCode\Data\Byte;
  14. use chillerlan\QRCode\Output\{
  15. QREps, QRFpdf, QRGdImageJPEG, QRGdImagePNG, QRGdImageWEBP, QRImagick, QRMarkupSVG, QRMarkupXML, 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 DATAMODES = [Mode::BYTE => Byte::class];
  24. public function initOptions():void{
  25. $options = [
  26. 'version' => $this->version->getVersionNumber(),
  27. 'eccLevel' => $this->eccLevel->getLevel(),
  28. 'connectPaths' => true,
  29. 'drawLightModules' => true,
  30. 'drawCircularModules' => true,
  31. 'gdImageUseUpscale' => false, // set to false to allow proper comparison
  32. ];
  33. $this->initQROptions($options);
  34. }
  35. #[Subject]
  36. public function QREps():void{
  37. (new QREps($this->options, $this->matrix))->dump();
  38. }
  39. #[Subject]
  40. public function QRFpdf():void{
  41. (new QRFpdf($this->options, $this->matrix))->dump();
  42. }
  43. /**
  44. * for some reason imageavif() is extremely slow, ~50x slower than imagepng()
  45. */
  46. #[Subject]
  47. # public function QRGdImageAVIF():void{
  48. # (new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix))->dump();
  49. # }
  50. #[Subject]
  51. public function QRGdImageJPEG():void{
  52. (new QRGdImageJPEG($this->options, $this->matrix))->dump();
  53. }
  54. #[Subject]
  55. public function QRGdImagePNG():void{
  56. (new QRGdImagePNG($this->options, $this->matrix))->dump();
  57. }
  58. #[Subject]
  59. public function QRGdImageWEBP():void{
  60. (new QRGdImageWEBP($this->options, $this->matrix))->dump();
  61. }
  62. #[Subject]
  63. public function QRImagick():void{
  64. (new QRImagick($this->options, $this->matrix))->dump();
  65. }
  66. #[Subject]
  67. public function QRMarkupSVG():void{
  68. (new QRMarkupSVG($this->options, $this->matrix))->dump();
  69. }
  70. #[Subject]
  71. public function QRMarkupXML():void{
  72. (new QRMarkupXML($this->options, $this->matrix))->dump();
  73. }
  74. #[Subject]
  75. public function QRStringJSON():void{
  76. (new QRStringJSON($this->options, $this->matrix))->dump();
  77. }
  78. }