Benchmarking mixed fetch-join with partial hydration
This commit is contained in:
parent
131aac531a
commit
608b3ed6a4
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Performance\Hydration;
|
||||
|
||||
use Doctrine\ORM\Internal\Hydration\ObjectHydrator;
|
||||
use Doctrine\ORM\Query;
|
||||
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 MixedQueryFetchJoinPartialObjectHydrationPerformanceBench
|
||||
{
|
||||
/**
|
||||
* @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',
|
||||
],
|
||||
[
|
||||
'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 < 2000; ++$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 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');
|
||||
}
|
||||
|
||||
public function benchHydration()
|
||||
{
|
||||
$this->hydrator->hydrateAll($this->stmt, $this->rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user