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

Move performance tests to phpbench #6575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c8a4159
Not a performance test
Ocramius May 26, 2016
25669c5
PHPBench base config
Ocramius May 26, 2016
37cb2c0
Benchmark autoloading definitions
Ocramius May 26, 2016
94adf97
Factory used to create a new entity manager
Ocramius May 26, 2016
f95c81b
Simple array hydration benchmark
Ocramius May 26, 2016
88ea1d3
Full hydration + query benchmark
Ocramius May 26, 2016
d8ddc47
Array hydration benchmark
Ocramius May 26, 2016
8774b02
Testing mixed array hydration (with scalars and fetch-joined results)
Ocramius May 26, 2016
0fdcc71
CS (alignment)
Ocramius May 26, 2016
f23359c
Renaming bench methods, for clarity
Ocramius May 26, 2016
97735cd
Partial hydration bench
Ocramius May 26, 2016
1e16cb8
Full object hydration benchmark
Ocramius May 26, 2016
131aac5
Removing unused `$entityManager` variable
Ocramius May 26, 2016
608b3ed
Benchmarking mixed fetch-join with partial hydration
Ocramius May 26, 2016
93dc028
Benchmarking full object hydration with fetch joins and mixed values
Ocramius May 26, 2016
fd27b22
Removing old `HydrationPerformanceTest`
Ocramius May 26, 2016
ef0edc8
Benchmarking simple insert operations (batched)
Ocramius May 26, 2016
cbb0c1b
Corrected class name - needs to end with `Bench`
Ocramius May 26, 2016
d51235f
Removing useless imports
Ocramius May 26, 2016
5401cb5
Removed old `InsertPerformanceTest` (moved to benchmark)
Ocramius May 26, 2016
29f55ea
Removing instantiation overhead from benchmark
Ocramius May 26, 2016
2692435
Benchmarking insert operations for a JTI
Ocramius May 26, 2016
c5a636e
Corrected benchmark name: benchmark affects a STI
Ocramius May 26, 2016
5240291
Benchmarking hydration of a STI
Ocramius May 26, 2016
8ec186f
Removing old inheritance persister test
Ocramius May 26, 2016
7515dd2
Removing old `PersisterPerformanceTest`
Ocramius May 26, 2016
b1bbad3
Unit of work changeset computation test
Ocramius May 26, 2016
77ce354
Removing old `UnitOfWorkPerformanceTest`
Ocramius May 26, 2016
d658364
Benchmarking instantiation of proxies
Ocramius May 26, 2016
d8140d7
Benchmarking proxy initialization logic
Ocramius May 26, 2016
f1bc1bb
Mocks required by the proxy performance benchmarks
Ocramius May 26, 2016
cfa9d78
Removing old `ProxyPerformanceTest`
Ocramius May 26, 2016
e07c90d
Add PHPBench to Travis-CI matrix
lcobucci Jul 23, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ lib/Doctrine/DBAL
.idea
vendor/
composer.lock
/tests/Doctrine/Performance/history.db
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ before_script:
- if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi
- if [ "$MYSQL_VERSION" == "5.7" ]; then bash ./tests/travis/install-mysql-5.7.sh; fi;
- if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi;
- if [[ $PHPBENCH = 1 ]]; then wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey; fi

script:
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib; fi
- ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS
- ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional
- if [[ $PHPBENCH = 1 ]]; then php phpbench.phar run -l dots --report=default; fi
- if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS; fi
- if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional; fi

after_script:
- if [[ "$PHPUNIT_FLAGS" != "" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
Expand All @@ -39,14 +41,15 @@ matrix:
env: DB=mariadb
addons:
mariadb: 10.1

- php: 7.1
env:
- DB=sqlite
- DEPENDENCIES='low'

- php: 7.1
env:
- DB=pgsql
- PHPSTAN=1

- php: 7.1
env: DB=mysql MYSQL_VERSION=5.7
Expand All @@ -55,6 +58,15 @@ matrix:
env: DB=mysql MYSQL_VERSION=5.7
sudo: required

- php: 7.1
env:
- DB=none
- PHPSTAN=1
- php: 7.1
env:
- DB=none
- PHPBENCH=1

allow_failures:
- php: nightly

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"psr-4": { "Doctrine\\ORM\\": "lib/Doctrine/ORM" }
},
"autoload-dev": {
"psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" }
"psr-4": {
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
"Doctrine\\Performance\\": "tests/Doctrine/Performance"
}
},
"bin": ["bin/doctrine"],
"extra": {
Expand Down
15 changes: 15 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bootstrap": "vendor/autoload.php",
"path": "tests/Doctrine/Performance",

"extensions": [
"PhpBench\\Extensions\\Dbal\\DbalExtension",
"PhpBench\\Extensions\\XDebug\\XDebugExtension"
],

"storage": "dbal",
"storage.dbal.connection": {
"driver": "pdo_sqlite",
"path": "tests/Doctrine/Performance/history.db"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Doctrine\Performance\ChangeSet;

use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Tests\Mocks\HydratorMockStatement;
use Doctrine\Tests\Models\CMS\CmsUser;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;

/**
* @BeforeMethods({"init"})
*/
final class UnitOfWorkComputeChangesBench
{
/**
* @var CmsUser[]
*/
private $users;

/**
* @var UnitOfWork
*/
private $unitOfWork;

public function init()
{
$this->unitOfWork = EntityManagerFactory::getEntityManager([])->getUnitOfWork();

for ($i = 1; $i <= 100; ++$i) {
$user = new CmsUser;
$user->id = $i;
$user->status = 'user';
$user->username = 'user' . $i;
$user->name = 'Mr.Smith-' . $i;
$this->users[] = $user;

$this->unitOfWork->registerManaged(
$user,
[
'id' => $i,
],
[
'id' => $user->id,
'status' => $user->status,
'username' => $user->username,
'name' => $user->name,
'address' => $user->address,
'email' => $user->email,
]
);
}

$this->unitOfWork->computeChangeSets();

if ($this->unitOfWork->getScheduledEntityUpdates()) {
throw new \LogicException('Unit of work should be clean at this stage');
}

foreach ($this->users AS $user) {
$user->status = 'other';
$user->username .= '++';
$user->name = str_replace('Mr.', 'Mrs.', $user->name);
}
}

public function benchChangeSetComputation()
{
$this->unitOfWork->computeChangeSets();
}
}

39 changes: 39 additions & 0 deletions tests/Doctrine/Performance/EntityManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Doctrine\Performance;

use Doctrine\DBAL\Driver\PDOSqlite\Driver;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Tools\SchemaTool;

final class EntityManagerFactory
{
public static function getEntityManager(array $schemaClassNames) : EntityManagerInterface
{
$config = new Configuration();

$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([
realpath(__DIR__ . '/Models/Cache'),
realpath(__DIR__ . '/Models/GeoNames')
], true));

$entityManager = EntityManager::create(
[
'driverClass' => Driver::class,
'memory' => true,
],
$config
);

(new SchemaTool($entityManager))
->createSchema(array_map([$entityManager, 'getClassMetadata'], $schemaClassNames));

return $entityManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Doctrine\Performance\Hydration;

use Doctrine\ORM\Internal\Hydration\ArrayHydrator;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Tests\Mocks\HydratorMockStatement;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsUser;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;

/**
* @BeforeMethods({"init"})
*/
final class MixedQueryFetchJoinArrayHydrationPerformanceBench
{
/**
* @var ArrayHydrator
*/
private $hydrator;

/**
* @var ResultSetMapping
*/
private $rsm;

/**
* @var HydratorMockStatement
*/
private $stmt;

public function init()
{
$resultSet = [
[
'u__id' => '1',
'u__status' => 'developer',
'u__username' => 'romanb',
'u__name' => 'Roman',
'sclr0' => 'ROMANB',
'p__phonenumber' => '42',
],
[
'u__id' => '1',
'u__status' => 'developer',
'u__username' => 'romanb',
'u__name' => 'Roman',
'sclr0' => 'ROMANB',
'p__phonenumber' => '43',
],
[
'u__id' => '2',
'u__status' => 'developer',
'u__username' => 'romanb',
'u__name' => 'Roman',
'sclr0' => 'JWAGE',
'p__phonenumber' => '91'
]
];

for ($i = 4; $i < 10000; ++$i) {
$resultSet[] = [
'u__id' => $i,
'u__status' => 'developer',
'u__username' => 'jwage',
'u__name' => 'Jonathan',
'sclr0' => 'JWAGE' . $i,
'p__phonenumber' => '91'
];
}

$this->stmt = new HydratorMockStatement($resultSet);
$this->hydrator = new ArrayHydrator(EntityManagerFactory::getEntityManager([]));
$this->rsm = new ResultSetMapping;

$this->rsm->addEntityResult(CmsUser::class, 'u');
$this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers');
$this->rsm->addFieldResult('u', 'u__id', 'id');
$this->rsm->addFieldResult('u', 'u__status', 'status');
$this->rsm->addFieldResult('u', 'u__username', 'username');
$this->rsm->addFieldResult('u', 'u__name', 'name');
$this->rsm->addScalarResult('sclr0', 'nameUpper');
$this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
}

public function benchHydration()
{
$this->hydrator->hydrateAll($this->stmt, $this->rsm);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Doctrine\Performance\Hydration;

use Doctrine\ORM\Internal\Hydration\ObjectHydrator;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Tests\Mocks\HydratorMockStatement;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsUser;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;

/**
* @BeforeMethods({"init"})
*/
final class MixedQueryFetchJoinFullObjectHydrationPerformanceBench
{
/**
* @var ObjectHydrator
*/
private $hydrator;

/**
* @var ResultSetMapping
*/
private $rsm;

/**
* @var HydratorMockStatement
*/
private $stmt;

public function init()
{
$resultSet = [
[
'u__id' => '1',
'u__status' => 'developer',
'u__username' => 'romanb',
'u__name' => 'Roman',
'sclr0' => 'ROMANB',
'p__phonenumber' => '42',
'a__id' => '1'
]
];

for ($i = 2; $i < 2000; ++$i) {
$resultSet[] = [
'u__id' => $i,
'u__status' => 'developer',
'u__username' => 'jwage',
'u__name' => 'Jonathan',
'sclr0' => 'JWAGE' . $i,
'p__phonenumber' => '91',
'a__id' => $i
];
}

$this->stmt = new HydratorMockStatement($resultSet);
$this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([]));
$this->rsm = new ResultSetMapping;

$this->rsm->addEntityResult(CmsUser::class, 'u');
$this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers');
$this->rsm->addFieldResult('u', 'u__id', 'id');
$this->rsm->addFieldResult('u', 'u__status', 'status');
$this->rsm->addFieldResult('u', 'u__username', 'username');
$this->rsm->addFieldResult('u', 'u__name', 'name');
$this->rsm->addScalarResult('sclr0', 'nameUpper');
$this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
$this->rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address');
$this->rsm->addFieldResult('a', 'a__id', 'id');
}

public function benchHydration()
{
$this->hydrator->hydrateAll($this->stmt, $this->rsm);
}
}

Loading