Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP perf: initial PHPBench integration #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ psalm: ensure
phpunit:
sh -c "${PHPQA_DOCKER_COMMAND} phpunit-7 --verbose"

benchmark: ensure
sh -c "${PHPQA_DOCKER_COMMAND} phpbench run --iterations=10 --report=aggregate"

phpunit-coverage: ensure
sh -c "${PHPQA_DOCKER_COMMAND} phpdbg -qrr /tools/phpunit-7 --verbose --coverage-text --log-junit=var/phpunit.junit.xml --coverage-xml var/coverage-xml/"

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"nicmart/tree": "^0.2,>= 0.2.4",
"nyholm/nsa": "^1.1",
"nyholm/symfony-bundle-test": "^1.4",
"phpbench/phpbench": "^0.16",
"phpoffice/phpspreadsheet": "^1.4,>= 1.4.1",
"phpunit/phpunit": "^7.0",
"symfony/console": "^3.4 || ^4.0",
Expand Down
18 changes: 18 additions & 0 deletions phpbench.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bootstrap": "vendor/autoload.php",
"path": "tests/Xezilaires/Performance",

"retry_threshold": 5,
"progress": "dots",

"annotation_import_use": true,
"extensions": [
"PhpBench\\Extensions\\Dbal\\DbalExtension",
"PhpBench\\Extensions\\XDebug\\XDebugExtension"
],
"storage": "dbal",
"storage.dbal.connection": {
"driver": "pdo_sqlite",
"path": "var/phpbench-history.db"
}
}
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ parameters:
paths:
- %currentWorkingDirectory%/tests/Xezilaires/Bridge/Spout/SpreadsheetTest.php
- %currentWorkingDirectory%/tests/Xezilaires/Functional/FunctionalTestCase.php
- %currentWorkingDirectory%/tests/Xezilaires/Performance/PerformanceTestCase.php
Binary file added resources/fixtures/massive.xlsx
Binary file not shown.
82 changes: 82 additions & 0 deletions tests/Xezilaires/Performance/PerformanceTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

/*
* This file is part of the xezilaires project.
*
* (c) Dalibor Karlović <dalibor@flexolabs.io>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Test\Performance;

use PhpBench\Benchmark\Metadata\Annotations as Bench;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Xezilaires\Bridge\Symfony\Serializer\ObjectSerializer;
use Xezilaires\Metadata\ColumnReference;
use Xezilaires\Metadata\Mapping;
use Xezilaires\Spreadsheet;
use Xezilaires\SpreadsheetIterator;
use Xezilaires\Test\FixtureTrait;
use Xezilaires\Test\Model\Product;

/**
* @Bench\BeforeMethods({"setUp"})
*/
abstract class PerformanceTestCase
{
use FixtureTrait;

/**
* @var Mapping
*/
private $mapping;

public function setUp(): void
{
$this->mapping = new Mapping(
Product::class,
[
'name' => new ColumnReference('A'),
'price' => new ColumnReference('B'),
],
[
'start' => 2,
]
);
}

/**
* @Bench\Assert(stat="mean", value="10")
* @Bench\Revs(1000)
*/
public function benchIteratorConstruction(): void
{
$this->getSpreadsheet($this->fixture('massive.xlsx'));
}

/**
* @Bench\Assert(stat="mean", value="10")
* @Bench\Revs(1000)
*/
public function benchIteratorIteration(): void
{
$iterator = $this->createIterator($this->getSpreadsheet($this->fixture('products.xlsx')), $this->mapping);

foreach ($iterator as $row) {
}
}

abstract protected function getSpreadsheet(\SplFileObject $file): Spreadsheet;

private function createIterator(Spreadsheet $spreadsheet, Mapping $mapping): SpreadsheetIterator
{
$serializer = new ObjectSerializer(new Serializer([new ObjectNormalizer()]));

return new SpreadsheetIterator($spreadsheet, $mapping, $serializer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of the xezilaires project.
*
* (c) Dalibor Karlović <dalibor@flexolabs.io>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Test\Performance\Spout;

use PhpBench\Benchmark\Metadata\Annotations as Bench;
use Xezilaires\Spreadsheet;
use Xezilaires\Test\Performance\PerformanceTestCase;

/**
* @internal
*
* @small
*/
final class SpoutSpreadsheetIteratorBench extends PerformanceTestCase
{
protected function getSpreadsheet(\SplFileObject $file): Spreadsheet
{
return new \Xezilaires\Bridge\Spout\Spreadsheet($file);
}
}