1
0
mirror of synced 2024-12-14 15:16:04 +03:00

[DDC-952] Add Persister hydration performance tests.

This commit is contained in:
Benjamin Eberlei 2011-03-15 23:22:37 +01:00
parent 1b46208aa5
commit 6d27b4760f
2 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,63 @@
<?php
namespace Doctrine\Tests\ORM\Performance;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('company');
parent::setUp();
}
public function testCompanyContract()
{
$person = new \Doctrine\Tests\Models\Company\CompanyEmployee();
$person->setName('Poor Sales Guy');
$person->setDepartment('Sales');
$person->setSalary(100);
$this->_em->persist($person);
for ($i = 0; $i < 33; $i++) {
$fix = new \Doctrine\Tests\Models\Company\CompanyFixContract();
$fix->setFixPrice(1000);
$fix->setSalesPerson($person);
$fix->markCompleted();
$this->_em->persist($fix);
$flex = new \Doctrine\Tests\Models\Company\CompanyFlexContract();
$flex->setSalesPerson($person);
$flex->setHoursWorked(100);
$flex->setPricePerHour(100);
$flex->markCompleted();
$this->_em->persist($flex);
$ultra = new \Doctrine\Tests\Models\Company\CompanyFlexUltraContract();
$ultra->setSalesPerson($person);
$ultra->setHoursWorked(150);
$ultra->setPricePerHour(150);
$ultra->setMaxPrice(7000);
$this->_em->persist($ultra);
}
$this->_em->flush();
$this->_em->clear();
$start = microtime(true);
$contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll();
echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n";
$this->assertEquals(99, count($contracts));
$this->_em->clear();
$start = microtime(true);
$contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll();
echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n";
$this->assertEquals(99, count($contracts));
}
}

View File

@ -0,0 +1,118 @@
<?php
namespace Doctrine\Tests\ORM\Performance;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Query;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsGroup;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsComment;
require_once __DIR__ . '/../../TestInit.php';
class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testFindCmsArticle()
{
$author = new CmsUser();
$author->name = "beberlei";
$author->status = "active";
$author->username = "beberlei";
$this->_em->persist($author);
$ids = array();
for ($i = 0; $i < 100; $i++) {
$article = new CmsArticle();
$article->text = "foo";
$article->topic = "bar";
$article->user = $author;
$this->_em->persist($article);
$ids[] = $article;
}
$this->_em->flush();
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
$this->_em->clear();
$start = microtime(true);
for ($i = 0; $i < 100; $i++) {
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
}
echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
$this->_em->clear();
$start = microtime(true);
for ($i = 0; $i < 100; $i++) {
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
}
echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
}
public function testFindCmsGroup()
{
for ($i = 0; $i < 100; $i++) {
$group = new CmsGroup();
$group->name = "foo" . $i;
$this->_em->persist($group);
}
$this->_em->flush();
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
}
public function testFindCmsUser()
{
for ($i = 0; $i < 100; $i++) {
$user = new CmsUser();
$user->name = "beberlei";
$user->status = "active";
$user->username = "beberlei".$i;
$this->_em->persist($user);
}
$this->_em->flush();
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
$this->_em->clear();
$start = microtime(true);
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
}
}