Completed
Pull Request — master (#21)
by Daniel
04:33 queued 02:05
created

GridBench   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 94
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 56 2
A grid_loading() 0 4 1
A grid_loading_with_form() 0 6 1
A provideNbObjects() 0 14 1
1
<?php
2
3
namespace Psi\Component\Grid\Benchmarks;
4
5
use Psi\Component\Grid\Tests\Functional\GridTestCase;
6
use Psi\Component\Grid\Tests\Model\Article;
7
8
/**
9
 * @BeforeMethods({"init"})
10
 * @Revs(100)
11
 * @Iterations(10)
12
 * @OutputTimeUnit("milliseconds")
13
 * @ParamProviders({"provideNbObjects"})
14
 */
15
class GridBench extends GridTestCase
16
{
17
    private $factory;
18
19
    public function init($params)
20
    {
21
        $nbObjects = $params['nb_objects'];
22
23
        $objects = [];
24
        for ($i = 0; $i < $nbObjects; $i++) {
25
            $objects[] = new Article('hello', $i);
26
        }
27
28
        $container = $this->createContainer([
29
            'mapping' => [
30
                Article::class => [
31
                    'grids' => [
32
                        'main' => [
33
                            'columns' => [
34
                                'title' => [
35
                                    'type' => 'property',
36
                                ],
37
                                'number' => [
38
                                    'type' => 'property',
39
                                ],
40
                            ],
41
                            'filters' => [
42
                                'title' => [
43
                                    'type' => 'string',
44
                                ],
45
                            ],
46
                        ],
47
                        'form' => [
48
                            'columns' => [
49
                                'select' => [
50
                                    'type' => 'select',
51
                                ],
52
                                'title' => [
53
                                    'type' => 'property',
54
                                ],
55
                                'number' => [
56
                                    'type' => 'property',
57
                                ],
58
                            ],
59
                            'filters' => [
60
                                'title' => [
61
                                    'type' => 'string',
62
                                ],
63
                            ],
64
                        ],
65
                    ],
66
                ],
67
            ],
68
            'collections' => [
69
                Article::class => $objects,
70
            ],
71
        ]);
72
73
        $this->factory = $container->get('grid.factory');
74
    }
75
76
    /**
77
     * @Subject()
78
     */
79
    public function grid_loading()
80
    {
81
        $this->factory->loadGrid(Article::class, []);
82
    }
83
84
    /**
85
     * @Subject()
86
     */
87
    public function grid_loading_with_form()
88
    {
89
        $this->factory->loadGrid(Article::class, [
90
            'variant' => 'form',
91
        ]);
92
    }
93
94
    public function provideNbObjects()
95
    {
96
        return [
97
            [
98
                'nb_objects' => 10,
99
            ],
100
            [
101
                'nb_objects' => 100,
102
            ],
103
            [
104
                'nb_objects' => 1000,
105
            ],
106
        ];
107
    }
108
}
109