Skip to content

Commit 884e935

Browse files
Add benchmarking
1 parent 4a26bba commit 884e935

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ testbench.yaml
1111
vendor
1212
node_modules
1313
.php-cs-fixer.cache
14+
.phpbench
15+
.DS_Store

benchmarks/DataBench.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
use Illuminate\Support\Collection;
4+
use Orchestra\Testbench\Concerns\CreatesApplication;
5+
use PhpBench\Attributes\BeforeMethods;
6+
use PhpBench\Attributes\Iterations;
7+
use PhpBench\Attributes\Revs;
8+
use PhpBench\Benchmark\Metadata\Annotations\Subject;
9+
use Spatie\LaravelData\LaravelDataServiceProvider;
10+
use Spatie\LaravelData\Tests\Fakes\ComplicatedData;
11+
use Spatie\LaravelData\Tests\Fakes\MultiNestedData;
12+
use Spatie\LaravelData\Tests\Fakes\SimpleData;
13+
14+
class DataBench
15+
{
16+
use CreatesApplication;
17+
18+
public function __construct()
19+
{
20+
$this->createApplication();
21+
}
22+
23+
protected function getPackageProviders($app)
24+
{
25+
return [
26+
LaravelDataServiceProvider::class,
27+
];
28+
}
29+
30+
#[Revs(500), Iterations(2)]
31+
public function benchData()
32+
{
33+
MultiNestedData::from([
34+
'nested' => ['simple' => 'Hello'],
35+
'nestedCollection' => [
36+
['simple' => 'I'],
37+
['simple' => 'am'],
38+
['simple' => 'groot'],
39+
],
40+
]);
41+
}
42+
43+
#[Revs(500), Iterations(2)]
44+
public function benchDataCollection()
45+
{
46+
$collection = Collection::times(
47+
15,
48+
fn() => [
49+
'withoutType' => 42,
50+
'int' => 42,
51+
'bool' => true,
52+
'float' => 3.14,
53+
'string' => 'Hello world',
54+
'array' => [1, 1, 2, 3, 5, 8],
55+
'nullable' => null,
56+
'mixed' => 42,
57+
'explicitCast' => '16-06-1994',
58+
'defaultCast' => '1994-05-16T12:00:00+01:00',
59+
'nestedData' => [
60+
'string' => 'hello',
61+
],
62+
'nestedCollection' => [
63+
['string' => 'never'],
64+
['string' => 'gonna'],
65+
['string' => 'give'],
66+
['string' => 'you'],
67+
['string' => 'up'],
68+
],
69+
]
70+
)->all();
71+
72+
ComplicatedData::collection($collection);
73+
}
74+
}

phpbench.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema":"./vendor/phpbench/phpbench/phpbench.schema.json",
3+
"runner.bootstrap": "vendor/autoload.php",
4+
"runner.path" : "benchmarks"
5+
}

phpbench.json.dist

-9
This file was deleted.

0 commit comments

Comments
 (0)