|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Infocyph\ArrayKit\Benchmarks; |
| 6 | + |
| 7 | +use Infocyph\ArrayKit\Array\ArrayMulti; |
| 8 | +use Infocyph\ArrayKit\Array\ArraySingle; |
| 9 | +use Infocyph\ArrayKit\Array\DotNotation; |
| 10 | +use Infocyph\ArrayKit\Config\Config; |
| 11 | +use PhpBench\Attributes\BeforeMethods; |
| 12 | +use PhpBench\Attributes\Iterations; |
| 13 | +use PhpBench\Attributes\Revs; |
| 14 | +use PhpBench\Attributes\Subject; |
| 15 | + |
| 16 | +#[Revs(500)] |
| 17 | +#[Iterations(5)] |
| 18 | +#[BeforeMethods('setUp')] |
| 19 | +final class CoreBench |
| 20 | +{ |
| 21 | + private Config $config; |
| 22 | + |
| 23 | + private array $dot = []; |
| 24 | + |
| 25 | + private array $nested = []; |
| 26 | + private array $single = []; |
| 27 | + |
| 28 | + public function setUp(): void |
| 29 | + { |
| 30 | + $this->single = [ |
| 31 | + 10, 20, 30, 40, 50, 10, 20, 30, 99, 120, 44, 55, |
| 32 | + 8, 15, 16, 23, 42, 7, 11, 13, 17, 19, 21, 34, |
| 33 | + 50, 51, 52, 53, 54, 55, 56, 57, |
| 34 | + ]; |
| 35 | + |
| 36 | + $this->nested = [ |
| 37 | + ['id' => 1, 'name' => 'Alice', 'scores' => [9, 8, 7]], |
| 38 | + ['id' => 2, 'name' => 'Bob', 'scores' => [6, 7, 8]], |
| 39 | + ['id' => 3, 'name' => 'Cara', 'scores' => [10, 9, 9]], |
| 40 | + ['id' => 4, 'name' => 'Dina', 'scores' => [7, 7, 7]], |
| 41 | + ['id' => 5, 'name' => 'Evan', 'scores' => [8, 8, 8]], |
| 42 | + ]; |
| 43 | + |
| 44 | + $this->dot = [ |
| 45 | + 'app' => ['name' => 'ArrayKit', 'env' => 'local'], |
| 46 | + 'db' => [ |
| 47 | + 'host' => 'localhost', |
| 48 | + 'port' => 3306, |
| 49 | + 'options' => ['timeout' => 5, 'ssl' => false], |
| 50 | + ], |
| 51 | + 'cache' => ['driver' => 'file', 'prefix' => 'arraykit'], |
| 52 | + ]; |
| 53 | + |
| 54 | + $this->config = new Config(); |
| 55 | + $this->config->loadArray($this->dot); |
| 56 | + } |
| 57 | + |
| 58 | + #[Subject] |
| 59 | + public function benchArrayMultiFlatten(): void |
| 60 | + { |
| 61 | + ArrayMulti::flatten($this->nested); |
| 62 | + } |
| 63 | + |
| 64 | + #[Subject] |
| 65 | + public function benchArraySingleUnique(): void |
| 66 | + { |
| 67 | + ArraySingle::unique($this->single); |
| 68 | + } |
| 69 | + |
| 70 | + #[Subject] |
| 71 | + public function benchConfigGet(): void |
| 72 | + { |
| 73 | + $this->config->get('db.options.timeout'); |
| 74 | + } |
| 75 | + |
| 76 | + #[Subject] |
| 77 | + public function benchDotNotationGet(): void |
| 78 | + { |
| 79 | + DotNotation::get($this->dot, 'db.options.timeout'); |
| 80 | + } |
| 81 | +} |
0 commit comments