From 8a88737ef4f1adcc220008f117d362e7b26e61fe Mon Sep 17 00:00:00 2001 From: "A. B. M. Mahmudul Hasan" Date: Mon, 13 Apr 2026 10:03:53 +0600 Subject: [PATCH] bench --- benchmarks/CoreBench.php | 81 ++++++++++++++++++++++++++++++++++++++++ examples/basic-usage.php | 16 ++++++++ 2 files changed, 97 insertions(+) create mode 100644 benchmarks/CoreBench.php create mode 100644 examples/basic-usage.php diff --git a/benchmarks/CoreBench.php b/benchmarks/CoreBench.php new file mode 100644 index 0000000..fc552e9 --- /dev/null +++ b/benchmarks/CoreBench.php @@ -0,0 +1,81 @@ +single = [ + 10, 20, 30, 40, 50, 10, 20, 30, 99, 120, 44, 55, + 8, 15, 16, 23, 42, 7, 11, 13, 17, 19, 21, 34, + 50, 51, 52, 53, 54, 55, 56, 57, + ]; + + $this->nested = [ + ['id' => 1, 'name' => 'Alice', 'scores' => [9, 8, 7]], + ['id' => 2, 'name' => 'Bob', 'scores' => [6, 7, 8]], + ['id' => 3, 'name' => 'Cara', 'scores' => [10, 9, 9]], + ['id' => 4, 'name' => 'Dina', 'scores' => [7, 7, 7]], + ['id' => 5, 'name' => 'Evan', 'scores' => [8, 8, 8]], + ]; + + $this->dot = [ + 'app' => ['name' => 'ArrayKit', 'env' => 'local'], + 'db' => [ + 'host' => 'localhost', + 'port' => 3306, + 'options' => ['timeout' => 5, 'ssl' => false], + ], + 'cache' => ['driver' => 'file', 'prefix' => 'arraykit'], + ]; + + $this->config = new Config(); + $this->config->loadArray($this->dot); + } + + #[Subject] + public function benchArrayMultiFlatten(): void + { + ArrayMulti::flatten($this->nested); + } + + #[Subject] + public function benchArraySingleUnique(): void + { + ArraySingle::unique($this->single); + } + + #[Subject] + public function benchConfigGet(): void + { + $this->config->get('db.options.timeout'); + } + + #[Subject] + public function benchDotNotationGet(): void + { + DotNotation::get($this->dot, 'db.options.timeout'); + } +} diff --git a/examples/basic-usage.php b/examples/basic-usage.php new file mode 100644 index 0000000..fcd70e2 --- /dev/null +++ b/examples/basic-usage.php @@ -0,0 +1,16 @@ +isList([1, 2, 3]); +$name = ArrayKit::dot()->get(['user' => ['name' => 'Alice']], 'user.name'); + +$config = ArrayKit::config(['app' => ['env' => 'local']]); +$env = $config->get('app.env'); + +$collection = ArrayKit::collection([1, 2, 3, 4]); +$sum = $collection->process()->sum(); + +unset($isList, $name, $env, $sum);