1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Benchmarking simple insert operations (batched)

This commit is contained in:
Marco Pivetta 2016-05-26 21:45:23 +02:00 committed by Luís Cobucci
parent fd27b22ad1
commit ef0edc8929
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C

View File

@ -0,0 +1,54 @@
<?php
namespace Doctrine\Performance\Hydration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Tests\Mocks\HydratorMockStatement;
use Doctrine\Tests\Models\CMS;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
/**
* @BeforeMethods({"init"})
*/
final class SimpleInsertPerformanceTest
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
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,
]);
}
public function benchHydration()
{
$batchSize = 20;
for ($i = 1; $i <= 10000; ++$i) {
$user = new CMS\CmsUser;
$user->status = 'user';
$user->username = 'user' . $i;
$user->name = 'Mr.Smith-' . $i;
$this->entityManager->persist($user);
if (! ($i % $batchSize)) {
$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
}