Issues (590)

bench/PrimeBench.php (5 issues)

Labels
1
<?php
2
3
namespace Bdf\Prime;
4
5
require_once __DIR__ . '/_files/BenchData.php';
6
7
use Bdf\Prime\Bench\BenchData;
8
use Bdf\Prime\Bench\User as BenchUser;
9
use Bdf\Prime\Cache\ArrayCache;
10
use Bdf\Prime\Connection\ConnectionConfig;
0 ignored issues
show
The type Bdf\Prime\Connection\ConnectionConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Bdf\Prime\Types\ArrayType;
12
13
/**
14
 * @Revs(100)
15
 */
16
class PrimeBench extends \BenchCaseAdapter
17
{
18
    /**
19
     * @var ServiceLocator
20
     */
21
    protected $prime;
22
23
    /**
24
     * @var BenchData
25
     */
26
    protected $data;
27
28
    /**
29
     * @var ArrayCache
30
     */
31
    protected $cache;
32
33
34
35
    public function setUp()
36
    {
37
        $this->cache = new ArrayCache();
38
        $this->prime = new ServiceLocator();
39
        $this->prime->connections()->declareConnection('test', BENCH_CONNECTION);
40
        $this->prime->connection('test')->getConfiguration()->getTypes()->register(ArrayType::class, 'array');
0 ignored issues
show
The method getConfiguration() does not exist on Bdf\Prime\Connection\ConnectionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Connection\ConnectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $this->prime->connection('test')->/** @scrutinizer ignore-call */ getConfiguration()->getTypes()->register(ArrayType::class, 'array');
Loading history...
41
        Locatorizable::configure($this->prime);
0 ignored issues
show
$this->prime of type Bdf\Prime\ServiceLocator is incompatible with the type Closure expected by parameter $locator of Bdf\Prime\Locatorizable::configure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        Locatorizable::configure(/** @scrutinizer ignore-type */ $this->prime);
Loading history...
42
43
        $this->data = new BenchData($this->prime);
44
        $this->data->addAllData();
45
    }
46
47
    /**
48
     *
49
     */
50
    public function tearDown()
51
    {
52
        $this->data->clear();
53
    }
54
55
    /**
56
     * @ParamProviders({"queryParams"})
57
     */
58
    public function bench($params)
59
    {
60
        list($name, $cache, $relations, $nb) = $params;
61
62
        $query = $this->prime->repository(BenchUser::class)->queries()->builder();
63
64
        if ($cache) {
65
            $query->setCache($this->cache)->useCache();
66
        }
67
68
        $query
69
            ->with($relations)
0 ignored issues
show
The method with() does not exist on Bdf\Prime\Query\QueryInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Bdf\Prime\Query\SqlQueryInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
            ->/** @scrutinizer ignore-call */ 
70
              with($relations)
Loading history...
70
            ->limit(100)
71
            ->all();
72
    }
73
74
    /**
75
     * @ParamProviders({"queryParams"})
76
     */
77
    public function bench_keyValue($params)
78
    {
79
        list($name, $cache, $relations, $nb) = $params;
80
81
        $query = $this->prime->repository(BenchUser::class)->queries()->keyValue();
82
83
        if ($cache) {
84
            $query->setCache($this->cache)->useCache();
85
        }
86
87
        $query
88
            ->with($relations)
0 ignored issues
show
The method with() does not exist on Bdf\Prime\Query\Contract...\KeyValueQueryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Query\Contract...\KeyValueQueryInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
            ->/** @scrutinizer ignore-call */ 
89
              with($relations)
Loading history...
89
            ->limit(100)
90
            ->all();
91
    }
92
    
93
    /**
94
     * 
95
     */
96
    public function queryParams()
97
    {
98
        return [
99
            ['loading class          ', true, 'customer.packs', 1],
100
            ['1 -cache               ', false, [], 1],
101
            ['1 +cache               ', true, [], 1],
102
            ['1 -cache hasOne        ', false, 'customer', 1],
103
            ['1 +cache hasOne        ', true, 'customer', 1],
104
            ['1 -cache hasOne hasMany', false, 'customer.packs', 1],
105
            ['1 +cache hasOne hasMany', true, 'customer.packs', 1],
106
107
            ['2 -cache               ', false, [], 2],
108
            ['2 +cache               ', true, [], 2],
109
            ['2 -cache hasOne        ', false, 'customer', 2],
110
            ['2 +cache hasOne        ', true, 'customer', 2],
111
            ['2 -cache hasOne hasMany', false, 'customer.packs', 2],
112
            ['2 +cache hasOne hasMany', true, 'customer.packs', 2],
113
        ];
114
    }
115
}
116
117
function convert($size) {
118
    return number_format($size/1024).' kb';
119
}
120
121
function profile($callback, $times) {
122
    $bench = [
123
        'queries'      => 0,
124
        'time'         => 0,
125
        'memory'       => 0,
126
    ];
127
    $start = microtime(true);
128
    $memory = memory_get_usage(true);
129
        
130
    for ($i = 0; $i < $times; $i++) {
131
        $callback();
132
    }
133
        
134
    $end = microtime(true);
135
    
136
    $delta = ($end - $start);
137
    
138
    $bench['time'] =  $delta;
139
    $bench['queries'] =  $times / $delta;
140
    $bench['memory'] =  memory_get_usage(true) - $memory;
141
    
142
    return $bench;
143
}