forked from neos/neos-development-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuntimeBench.php
176 lines (163 loc) · 5.48 KB
/
RuntimeBench.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace Neos\Fusion\Tests\Benchmark;
/*
* This file is part of the Neos.Fusion package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Eel\CompilingEvaluator;
use Neos\Fusion\Core\FusionConfiguration;
use Neos\Fusion\Core\FusionGlobals;
use Neos\Fusion\Core\RuntimeFactory;
/**
* A benchmark to test the Fusion runtime
*
* @BeforeMethods({"init"})
*/
class RuntimeBench
{
/**
* @var \Neos\Fusion\Core\Runtime
*/
protected $runtime;
public function init()
{
$fusionConfiguration = [
'obj' => [
'__objectType' => 'Neos.Fusion:Value',
'__value' => null,
'__eelExpression' => null,
'value' => 'Hello obj!'
],
'value' => [
'__objectType' => null,
'__value' => 'Hello value!',
'__eelExpression' => null
],
'expr' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => 'foo'
],
'longpath' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'sub' => [
'__objectType' => null,
'__value' => null,
'__eelExpression' => null,
'value' => [
'__objectType' => null,
'__value' => 'Hello longpath!',
'__eelExpression' => null
],
]
]
]
]
]
]
],
'__prototypes' => [
'Neos.Fusion:Value' => [
'__meta' => [
'class' => \Neos\Fusion\FusionObjects\ValueImplementation::class
]
]
]
];
$this->runtime = (new RuntimeFactory())->createFromConfiguration(FusionConfiguration::fromArray($fusionConfiguration), FusionGlobals::createEmpty());
// Build an EEL evaluator suitable for benchmarking
$evaluator = $this->buildEelEvaluator();
\Neos\Utility\ObjectAccess::setProperty($this->runtime, 'eelEvaluator', $evaluator, true);
$this->runtime->pushContextArray([
'foo' => 'Hello expression!'
]);
}
/**
* Benchmark evaluation of a path that is an object
*
* @Iterations(10)
* @Revs(10000)
*/
public function bench_evaluate_obj()
{
$x = $this->runtime->evaluate('obj');
if ($x !== 'Hello obj!') {
throw new \Exception('assertion failed');
}
}
/**
* Benchmark evaluation of a path that is a value
*
* @Iterations(10)
* @Revs(10000)
*/
public function bench_evaluate_value()
{
$x = $this->runtime->evaluate('value');
if ($x !== 'Hello value!') {
throw new \Exception('assertion failed');
}
}
/**
* Benchmark evaluation of a path that is an expression
*
* @Iterations(10)
* @Revs(10000)
*/
public function bench_evaluate_expr()
{
$x = $this->runtime->evaluate('expr');
if ($x !== 'Hello expression!') {
throw new \Exception('assertion failed');
}
}
/**
* Benchmark evaluation of a long path to make sure caching of effective configuration is correct
*
* @Iterations(10)
* @Revs(10000)
*/
public function bench_evaluate_longpath_value()
{
$x = $this->runtime->evaluate('longpath/sub/sub/sub/sub/sub/sub/value');
if ($x !== 'Hello longpath!') {
throw new \Exception('assertion failed');
}
}
private function buildEelEvaluator(): CompilingEvaluator
{
$evaluator = new CompilingEvaluator();
$backend = new \Neos\Cache\Backend\TransientMemoryBackend();
$frontend = new \Neos\Cache\Frontend\StringFrontend('expressions', $backend);
$backend->setCache($frontend);
$evaluator->injectExpressionCache($frontend);
return $evaluator;
}
}