-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 #6575 from lcobucci/improvement/move-performance-t…
…ests-to-phpbench Move performance tests to phpbench
- Loading branch information
Showing
30 changed files
with
1,595 additions
and
951 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ lib/Doctrine/DBAL | |
.idea | ||
vendor/ | ||
composer.lock | ||
/tests/Doctrine/Performance/history.db |
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
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,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" | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php
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,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(); | ||
} | ||
} | ||
|
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,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; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php
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,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); | ||
} | ||
} | ||
|
81 changes: 81 additions & 0 deletions
81
...Doctrine/Performance/Hydration/MixedQueryFetchJoinFullObjectHydrationPerformanceBench.php
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,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); | ||
} | ||
} | ||
|
Oops, something went wrong.