Skip to content

Commit 1da56ac

Browse files
authored
Merge pull request #17 from infocyph/feature/improvement-25
bench
2 parents 00b454d + 0c94cd5 commit 1da56ac

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

benchmarks/CoreBench.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
}

examples/basic-usage.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Infocyph\ArrayKit\ArrayKit;
6+
7+
$isList = ArrayKit::single()->isList([1, 2, 3]);
8+
$name = ArrayKit::dot()->get(['user' => ['name' => 'Alice']], 'user.name');
9+
10+
$config = ArrayKit::config(['app' => ['env' => 'local']]);
11+
$env = $config->get('app.env');
12+
13+
$collection = ArrayKit::collection([1, 2, 3, 4]);
14+
$sum = $collection->process()->sum();
15+
16+
unset($isList, $name, $env, $sum);

0 commit comments

Comments
 (0)