Failed Conditions
Pull Request — master (#6575)
by Luís
14:40
created

SimpleInsertPerformanceBench::benchHydration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace Doctrine\Performance\Hydration;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Query;
7
use Doctrine\Performance\EntityManagerFactory;
8
use Doctrine\Tests\Mocks\HydratorMockStatement;
9
use Doctrine\Tests\Models\CMS;
10
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
11
12
/**
13
 * @BeforeMethods({"init"})
14
 */
15
final class SimpleInsertPerformanceBench
16
{
17
    /**
18
     * @var EntityManagerInterface
19
     */
20
    private $entityManager;
21
22
    /**
23
     * @var CMS\CmsUser[]
24
     */
25
    private $users;
26
27
    public function init()
28
    {
29
        $this->entityManager = EntityManagerFactory::getEntityManager([
30
            CMS\CmsUser::class,
31
            CMS\CmsPhonenumber::class,
32
            CMS\CmsAddress::class,
33
            CMS\CmsEmail::class,
34
            CMS\CmsGroup::class,
35
            CMS\CmsTag::class,
36
            CMS\CmsArticle::class,
37
            CMS\CmsComment::class,
38
        ]);
39
40
        for ($i = 1; $i <= 10000; ++$i) {
41
            $user           = new CMS\CmsUser;
42
            $user->status   = 'user';
43
            $user->username = 'user' . $i;
44
            $user->name     = 'Mr.Smith-' . $i;
45
46
            $this->users[$i] = $user;
47
        }
48
    }
49
50
    public function benchHydration()
51
    {
52
        foreach ($this->users as $key => $user) {
53
            $this->entityManager->persist($user);
54
55
            if (! ($key % 20)) {
56
                $this->entityManager->flush();
57
                $this->entityManager->clear();
58
            }
59
        }
60
    }
61
}
62