generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from spatie/benchmarks-pipeline
Benchmarks pipeline
- Loading branch information
Showing
15 changed files
with
316 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.php' | ||
- 'phpbench.json' | ||
pull_request: | ||
paths: | ||
- '**.php' | ||
- 'phpbench.json' | ||
|
||
jobs: | ||
phpstan: | ||
name: phpstan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
coverage: none | ||
|
||
- name: Install composer dependencies | ||
uses: ramsey/composer-install@v2 | ||
|
||
- name: Run Benchmark | ||
run: composer benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ testbench.yaml | |
vendor | ||
node_modules | ||
.php-cs-fixer.cache | ||
.phpbench | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
use Carbon\CarbonImmutable; | ||
use Illuminate\Support\Collection; | ||
use Orchestra\Testbench\Concerns\CreatesApplication; | ||
use PhpBench\Attributes\BeforeMethods; | ||
use PhpBench\Attributes\Iterations; | ||
use PhpBench\Attributes\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Subject; | ||
use Spatie\LaravelData\DataCollection; | ||
use Spatie\LaravelData\LaravelDataServiceProvider; | ||
use Spatie\LaravelData\Optional; | ||
use Spatie\LaravelData\Tests\Fakes\ComplicatedData; | ||
use Spatie\LaravelData\Tests\Fakes\MultiNestedData; | ||
use Spatie\LaravelData\Tests\Fakes\NestedData; | ||
use Spatie\LaravelData\Tests\Fakes\SimpleData; | ||
|
||
class DataBench | ||
{ | ||
use CreatesApplication; | ||
|
||
public function __construct() | ||
{ | ||
$this->createApplication(); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
LaravelDataServiceProvider::class, | ||
]; | ||
} | ||
|
||
#[Revs(500), Iterations(2)] | ||
public function benchDataCreation() | ||
{ | ||
MultiNestedData::from([ | ||
'nested' => ['simple' => 'Hello'], | ||
'nestedCollection' => [ | ||
['simple' => 'I'], | ||
['simple' => 'am'], | ||
['simple' => 'groot'], | ||
], | ||
]); | ||
} | ||
|
||
#[Revs(500), Iterations(2)] | ||
public function benchDataTransformation() | ||
{ | ||
$data = new MultiNestedData( | ||
new NestedData(new SimpleData('Hello')), | ||
new DataCollection(NestedData::class, [ | ||
new NestedData(new SimpleData('I')), | ||
new NestedData(new SimpleData('am')), | ||
new NestedData(new SimpleData('groot')), | ||
]) | ||
); | ||
|
||
$data->toArray(); | ||
} | ||
|
||
#[Revs(500), Iterations(2)] | ||
public function benchDataCollectionCreation() | ||
{ | ||
$collection = Collection::times( | ||
15, | ||
fn() => [ | ||
'withoutType' => 42, | ||
'int' => 42, | ||
'bool' => true, | ||
'float' => 3.14, | ||
'string' => 'Hello world', | ||
'array' => [1, 1, 2, 3, 5, 8], | ||
'nullable' => null, | ||
'mixed' => 42, | ||
'explicitCast' => '16-06-1994', | ||
'defaultCast' => '1994-05-16T12:00:00+01:00', | ||
'nestedData' => [ | ||
'string' => 'hello', | ||
], | ||
'nestedCollection' => [ | ||
['string' => 'never'], | ||
['string' => 'gonna'], | ||
['string' => 'give'], | ||
['string' => 'you'], | ||
['string' => 'up'], | ||
], | ||
] | ||
)->all(); | ||
|
||
ComplicatedData::collection($collection); | ||
} | ||
|
||
#[Revs(500), Iterations(2)] | ||
public function benchDataCollectionTransformation() | ||
{ | ||
$collection = Collection::times( | ||
15, | ||
fn() => new ComplicatedData( | ||
42, | ||
42, | ||
true, | ||
3.14, | ||
'Hello World', | ||
[1, 1, 2, 3, 5, 8], | ||
null, | ||
Optional::create(), | ||
42, | ||
CarbonImmutable::create(1994,05,16), | ||
new DateTime('1994-05-16T12:00:00+01:00'), | ||
new SimpleData('hello'), | ||
new DataCollection(NestedData::class, [ | ||
new NestedData(new SimpleData('I')), | ||
new NestedData(new SimpleData('am')), | ||
new NestedData(new SimpleData('groot')), | ||
]) | ||
) | ||
)->all(); | ||
|
||
$collection = ComplicatedData::collection($collection); | ||
|
||
$collection->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema":"./vendor/phpbench/phpbench/phpbench.schema.json", | ||
"runner.bootstrap": "vendor/autoload.php", | ||
"runner.path" : "benchmarks" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.