|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Goat\Benchmark\Converter; |
| 6 | + |
| 7 | +use MakinaCorpus\QueryBuilder\Converter\Converter; |
| 8 | +use MakinaCorpus\QueryBuilder\Type\Type; |
| 9 | +use Ramsey\Uuid\Uuid; |
| 10 | +use Ramsey\Uuid\UuidInterface; |
| 11 | + |
| 12 | +/** |
| 13 | + * @BeforeMethods({"setUp"}) |
| 14 | + */ |
| 15 | +final class ConversionBench |
| 16 | +{ |
| 17 | + private Converter $converter; |
| 18 | + |
| 19 | + private array $arrayData; |
| 20 | + private string $arrayDataAsString; |
| 21 | + private Type $arrayType; |
| 22 | + private Type $intType; |
| 23 | + private UuidInterface $ramseyUuidData; |
| 24 | + private string $ramseyUuidDataAsString; |
| 25 | + private Type $ramseyUuidType; |
| 26 | + |
| 27 | + public function setUp(): void |
| 28 | + { |
| 29 | + $this->converter = new Converter(); |
| 30 | + |
| 31 | + $this->arrayData = ["foo", "bar", "l''och"]; |
| 32 | + $this->arrayDataAsString = "{foo,bar,l''och}"; |
| 33 | + // $this->arrayType = Type::varchar()->toArray(); |
| 34 | + // $this->intType = Type::int(); |
| 35 | + $this->ramseyUuidData = Uuid::fromString('a9336bfe-1a3b-4d14-a2da-38b819da0e96'); |
| 36 | + $this->ramseyUuidDataAsString = 'a9336bfe-1a3b-4d14-a2da-38b819da0e96'; |
| 37 | + // $this->ramseyUuidType = Type::uuid(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @Revs(3000) |
| 42 | + * @Iterations(5) |
| 43 | + */ |
| 44 | + public function benchIntFromSql(): void |
| 45 | + { |
| 46 | + $this->converter->fromSQL('int', '152485788'); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @Revs(3000) |
| 51 | + * @Iterations(5) |
| 52 | + */ |
| 53 | + public function benchIntToSql(): void |
| 54 | + { |
| 55 | + $this->converter->toSQL(152485788, 'int8'); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @Revs(3000) |
| 60 | + * @Iterations(5) |
| 61 | + */ |
| 62 | + public function benchIntToSqlNullType(): void |
| 63 | + { |
| 64 | + $this->converter->toSQL(152485788, null); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @Revs(3000) |
| 69 | + * @Iterations(5) |
| 70 | + * |
| 71 | + public function benchIntToSqlWithType(): void |
| 72 | + { |
| 73 | + $this->converter->toSQL(152485788, $this->intType); |
| 74 | + } |
| 75 | + */ |
| 76 | + |
| 77 | + /** |
| 78 | + * @Revs(3000) |
| 79 | + * @Iterations(5) |
| 80 | + */ |
| 81 | + public function benchRamseyUuidFromSql(): void |
| 82 | + { |
| 83 | + $this->converter->fromSQL(UuidInterface::class, $this->ramseyUuidDataAsString); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @Revs(3000) |
| 88 | + * @Iterations(5) |
| 89 | + */ |
| 90 | + public function benchRamseyUuidToSql(): void |
| 91 | + { |
| 92 | + $this->converter->toSQL($this->ramseyUuidData, 'uuid'); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @Revs(3000) |
| 97 | + * @Iterations(5) |
| 98 | + */ |
| 99 | + public function benchRamseyUuidToSqlNullType(): void |
| 100 | + { |
| 101 | + $this->converter->toSQL($this->ramseyUuidData, null); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @Revs(3000) |
| 106 | + * @Iterations(5) |
| 107 | + * |
| 108 | + public function benchRamseyUuidToSqlWithType(): void |
| 109 | + { |
| 110 | + $this->converter->toSQL($this->ramseyUuidData, $this->ramseyUuidType); |
| 111 | + } |
| 112 | + */ |
| 113 | + |
| 114 | + /** |
| 115 | + * @Revs(3000) |
| 116 | + * @Iterations(5) |
| 117 | + */ |
| 118 | + public function benchArrayFromSql(): void |
| 119 | + { |
| 120 | + $this->converter->fromSQL('string[]', $this->arrayDataAsString); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * @Revs(3000) |
| 125 | + * @Iterations(5) |
| 126 | + */ |
| 127 | + public function benchArrayToSql(): void |
| 128 | + { |
| 129 | + $this->converter->toSQL($this->arrayData, 'varchar[]'); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * @Revs(3000) |
| 134 | + * @Iterations(5) |
| 135 | + */ |
| 136 | + public function benchArrayToSqlNullType(): void |
| 137 | + { |
| 138 | + $this->converter->toSQL($this->arrayData, null); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @Revs(3000) |
| 143 | + * @Iterations(5) |
| 144 | + * |
| 145 | + public function benchArrayToSqlWithType(): void |
| 146 | + { |
| 147 | + $this->converter->toSQL($this->arrayData, $this->arrayType); |
| 148 | + } |
| 149 | + */ |
| 150 | +} |
0 commit comments