2016-05-26 21:45:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Performance\Hydration;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\Performance\EntityManagerFactory;
|
|
|
|
use Doctrine\Tests\Models\CMS;
|
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @BeforeMethods({"init"})
|
|
|
|
*/
|
2016-05-26 21:46:02 +02:00
|
|
|
final class SimpleInsertPerformanceBench
|
2016-05-26 21:45:23 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var EntityManagerInterface
|
|
|
|
*/
|
|
|
|
private $entityManager;
|
|
|
|
|
2016-05-26 21:50:59 +02:00
|
|
|
/**
|
|
|
|
* @var CMS\CmsUser[]
|
|
|
|
*/
|
|
|
|
private $users;
|
|
|
|
|
2017-08-26 16:41:03 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $tableName;
|
|
|
|
|
2016-05-26 21:45:23 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->entityManager = EntityManagerFactory::getEntityManager([
|
|
|
|
CMS\CmsUser::class,
|
|
|
|
CMS\CmsPhonenumber::class,
|
|
|
|
CMS\CmsAddress::class,
|
|
|
|
CMS\CmsEmail::class,
|
|
|
|
CMS\CmsGroup::class,
|
|
|
|
CMS\CmsTag::class,
|
|
|
|
CMS\CmsArticle::class,
|
|
|
|
CMS\CmsComment::class,
|
|
|
|
]);
|
|
|
|
|
|
|
|
for ($i = 1; $i <= 10000; ++$i) {
|
|
|
|
$user = new CMS\CmsUser;
|
|
|
|
$user->status = 'user';
|
|
|
|
$user->username = 'user' . $i;
|
|
|
|
$user->name = 'Mr.Smith-' . $i;
|
|
|
|
|
2016-05-26 21:50:59 +02:00
|
|
|
$this->users[$i] = $user;
|
|
|
|
}
|
2017-08-26 16:41:03 +02:00
|
|
|
|
|
|
|
$this->tableName = $this->entityManager->getClassMetadata(CMS\CmsUser::class)->getTableName();
|
2016-05-26 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function benchHydration()
|
|
|
|
{
|
2017-08-26 16:41:03 +02:00
|
|
|
// Yes, this is a lot of overhead, but I have no better solution other than
|
|
|
|
// completely mocking out the DB, which would be silly (query impact is
|
|
|
|
// necessarily part of our benchmarks)
|
|
|
|
$this->entityManager->getConnection()->executeQuery('DELETE FROM ' . $this->tableName)->execute();
|
|
|
|
|
2016-05-26 21:50:59 +02:00
|
|
|
foreach ($this->users as $key => $user) {
|
2016-05-26 21:45:23 +02:00
|
|
|
$this->entityManager->persist($user);
|
|
|
|
|
2016-05-26 21:50:59 +02:00
|
|
|
if (! ($key % 20)) {
|
2016-05-26 21:45:23 +02:00
|
|
|
$this->entityManager->flush();
|
|
|
|
$this->entityManager->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|