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

benchInitializationOfAlreadyInitializedCmsEmployees()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace Doctrine\Performance\LazyLoading;
4
5
use Doctrine\ORM\Proxy\Proxy;
6
use Doctrine\Performance\EntityManagerFactory;
7
use Doctrine\Performance\Mock\NonProxyLoadingEntityManager;
8
use Doctrine\Tests\Models\CMS\CmsEmployee;
9
use Doctrine\Tests\Models\CMS\CmsUser;
10
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
11
12
/**
13
 * @BeforeMethods({"init"})
14
 */
15
final class ProxyInitializationTimeBench
16
{
17
    /**
18
     * @var Proxy[]
19
     */
20
    private $cmsUsers;
21
22
    /**
23
     * @var Proxy[]
24
     */
25
    private $cmsEmployees;
26
27
    /**
28
     * @var Proxy[]
29
     */
30
    private $initializedUsers;
31
32
    /**
33
     * @var Proxy[]
34
     */
35
    private $initializedEmployees;
36
37
    public function init()
38
    {
39
        $proxyFactory = (new NonProxyLoadingEntityManager(EntityManagerFactory::getEntityManager([])))
40
            ->getProxyFactory();
41
42
        for ($i = 0; $i < 10000; ++$i) {
43
            $this->cmsUsers[$i]             = $proxyFactory->getProxy(CmsUser::class, ['id' => $i]);
44
            $this->cmsEmployees[$i]         = $proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]);
45
            $this->initializedUsers[$i]     = $proxyFactory->getProxy(CmsUser::class, ['id' => $i]);
46
            $this->initializedEmployees[$i] = $proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]);
47
48
            $this->initializedUsers[$i]->__load();
49
            $this->initializedEmployees[$i]->__load();
50
        }
51
    }
52
53
    public function benchCmsUserInitialization()
54
    {
55
        foreach ($this->cmsUsers as $proxy) {
56
            $proxy->__load();
57
        }
58
    }
59
60
    public function benchCmsEmployeeInitialization()
61
    {
62
        foreach ($this->cmsEmployees as $proxy) {
63
            $proxy->__load();
64
        }
65
    }
66
67
    public function benchInitializationOfAlreadyInitializedCmsUsers()
68
    {
69
        foreach ($this->initializedUsers as $proxy) {
70
            $proxy->__load();
71
        }
72
    }
73
74
    public function benchInitializationOfAlreadyInitializedCmsEmployees()
75
    {
76
        foreach ($this->initializedEmployees as $proxy) {
77
            $proxy->__load();
78
        }
79
    }
80
}
81
82