2009-05-14 18:57:08 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Performance;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
use Doctrine\Tests\Mocks\HydratorMockStatement;
|
|
|
|
use Doctrine\ORM\Query\ResultSetMapping;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests to prevent serious performance regressions.
|
|
|
|
*
|
|
|
|
* IMPORTANT: Be sure to run these tests withoug xdebug or similar tools that
|
|
|
|
* seriously degrade performance.
|
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
*/
|
|
|
|
class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Times for comparison:
|
|
|
|
*
|
2009-07-15 10:46:43 +04:00
|
|
|
* [romanb: 10000 rows => 1 second]
|
2009-05-14 18:57:08 +04:00
|
|
|
*
|
2009-07-15 10:46:43 +04:00
|
|
|
* MAXIMUM TIME: 2 seconds
|
2009-05-14 18:57:08 +04:00
|
|
|
*/
|
2009-05-28 15:13:12 +04:00
|
|
|
public function testSimpleQueryArrayHydrationPerformance()
|
2009-05-14 18:57:08 +04:00
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-24 14:38:37 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-05-14 18:57:08 +04:00
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__status', 'status');
|
|
|
|
$rsm->addFieldResult('u', 'u__username', 'username');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
//row1
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ($i = 4; $i < 10000; ++$i) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'u__id' => $i,
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'jwage',
|
|
|
|
'u__name' => 'Jonathan',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
|
|
|
|
2009-07-15 10:46:43 +04:00
|
|
|
$this->setMaxRunningTime(2);
|
2009-05-28 15:13:12 +04:00
|
|
|
$s = microtime(true);
|
2009-05-14 18:57:08 +04:00
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
2009-05-28 15:13:12 +04:00
|
|
|
$e = microtime(true);
|
|
|
|
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
|
2009-05-14 18:57:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Times for comparison:
|
|
|
|
*
|
2009-07-15 10:46:43 +04:00
|
|
|
* [romanb: 10000 rows => 1.4 seconds]
|
2009-05-14 18:57:08 +04:00
|
|
|
*
|
2009-07-15 10:46:43 +04:00
|
|
|
* MAXIMUM TIME: 3 seconds
|
2009-05-14 18:57:08 +04:00
|
|
|
*/
|
2009-05-28 15:13:12 +04:00
|
|
|
public function testMixedQueryFetchJoinArrayHydrationPerformance()
|
2009-05-14 18:57:08 +04:00
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-24 14:38:37 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-05-14 18:57:08 +04:00
|
|
|
$rsm->addJoinedEntityResult(
|
2009-05-24 14:38:37 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsPhonenumber',
|
2009-05-14 18:57:08 +04:00
|
|
|
'p',
|
|
|
|
'u',
|
2009-08-11 14:51:38 +04:00
|
|
|
'phonenumbers'
|
2009-05-14 18:57:08 +04:00
|
|
|
);
|
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__status', 'status');
|
|
|
|
$rsm->addFieldResult('u', 'u__username', 'username');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
$rsm->addScalarResult('sclr0', 'nameUpper');
|
|
|
|
$rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
|
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
//row1
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'ROMANB',
|
|
|
|
'p__phonenumber' => '42',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'ROMANB',
|
|
|
|
'p__phonenumber' => '43',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'JWAGE',
|
|
|
|
'p__phonenumber' => '91'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ($i = 4; $i < 10000; ++$i) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'u__id' => $i,
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'jwage',
|
|
|
|
'u__name' => 'Jonathan',
|
|
|
|
'sclr0' => 'JWAGE' . $i,
|
|
|
|
'p__phonenumber' => '91'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
|
|
|
|
2009-07-15 10:46:43 +04:00
|
|
|
$this->setMaxRunningTime(3);
|
2009-05-28 15:13:12 +04:00
|
|
|
$s = microtime(true);
|
2009-05-14 18:57:08 +04:00
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
2009-05-28 15:13:12 +04:00
|
|
|
$e = microtime(true);
|
|
|
|
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
|
2009-05-14 18:57:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-07-15 10:46:43 +04:00
|
|
|
* [romanb: 10000 rows => 1.5 seconds]
|
2009-05-14 18:57:08 +04:00
|
|
|
*
|
2009-07-15 10:46:43 +04:00
|
|
|
* MAXIMUM TIME: 3 seconds
|
2009-05-14 18:57:08 +04:00
|
|
|
*/
|
|
|
|
public function testSimpleQueryObjectHydrationPerformance()
|
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-24 14:38:37 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-05-14 18:57:08 +04:00
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__status', 'status');
|
|
|
|
$rsm->addFieldResult('u', 'u__username', 'username');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
//row1
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ($i = 4; $i < 10000; ++$i) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'u__id' => $i,
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'jwage',
|
|
|
|
'u__name' => 'Jonathan',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
|
|
|
|
2009-07-15 10:46:43 +04:00
|
|
|
$this->setMaxRunningTime(3);
|
2009-05-28 15:13:12 +04:00
|
|
|
$s = microtime(true);
|
2009-05-14 18:57:08 +04:00
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
2009-05-28 15:13:12 +04:00
|
|
|
$e = microtime(true);
|
|
|
|
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
|
2009-05-14 18:57:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* [romanb: 2000 rows => 0.4 seconds]
|
2009-05-14 18:57:08 +04:00
|
|
|
*
|
2009-08-03 17:25:56 +04:00
|
|
|
* MAXIMUM TIME: 1 second
|
2009-05-14 18:57:08 +04:00
|
|
|
*/
|
|
|
|
public function testMixedQueryFetchJoinObjectHydrationPerformance()
|
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-24 14:38:37 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-05-14 18:57:08 +04:00
|
|
|
$rsm->addJoinedEntityResult(
|
2009-05-24 14:38:37 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsPhonenumber',
|
2009-05-14 18:57:08 +04:00
|
|
|
'p',
|
|
|
|
'u',
|
2009-08-11 14:51:38 +04:00
|
|
|
'phonenumbers'
|
2009-05-14 18:57:08 +04:00
|
|
|
);
|
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__status', 'status');
|
|
|
|
$rsm->addFieldResult('u', 'u__username', 'username');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
$rsm->addScalarResult('sclr0', 'nameUpper');
|
|
|
|
$rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
|
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
//row1
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'ROMANB',
|
|
|
|
'p__phonenumber' => '42',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'ROMANB',
|
|
|
|
'p__phonenumber' => '43',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
'sclr0' => 'JWAGE',
|
|
|
|
'p__phonenumber' => '91'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ($i = 4; $i < 2000; ++$i) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'u__id' => $i,
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'jwage',
|
|
|
|
'u__name' => 'Jonathan',
|
|
|
|
'sclr0' => 'JWAGE' . $i,
|
|
|
|
'p__phonenumber' => '91'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
|
|
|
|
2009-08-03 17:25:56 +04:00
|
|
|
$this->setMaxRunningTime(1);
|
2009-05-28 15:13:12 +04:00
|
|
|
$s = microtime(true);
|
2009-05-14 18:57:08 +04:00
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
2009-05-28 15:13:12 +04:00
|
|
|
$e = microtime(true);
|
|
|
|
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
|
2009-05-14 18:57:08 +04:00
|
|
|
}
|
2009-07-21 13:25:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Times for comparison:
|
|
|
|
*
|
|
|
|
* [romanb: 10000 rows => 0.7 seconds]
|
|
|
|
*
|
|
|
|
* MAXIMUM TIME: 1 second
|
|
|
|
*/
|
|
|
|
public function testSimpleQueryScalarHydrationPerformance()
|
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__status', 'status');
|
|
|
|
$rsm->addFieldResult('u', 'u__username', 'username');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
//row1
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'romanb',
|
|
|
|
'u__name' => 'Roman',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ($i = 4; $i < 10000; ++$i) {
|
|
|
|
$resultSet[] = array(
|
|
|
|
'u__id' => $i,
|
|
|
|
'u__status' => 'developer',
|
|
|
|
'u__username' => 'jwage',
|
|
|
|
'u__name' => 'Jonathan',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
|
|
|
|
|
|
|
|
$this->setMaxRunningTime(1);
|
|
|
|
$s = microtime(true);
|
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
|
|
|
$e = microtime(true);
|
|
|
|
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
|
|
|
|
}
|
2009-05-14 18:57:08 +04:00
|
|
|
}
|
|
|
|
|