ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
bench.php
Go to the documentation of this file.
1
<?
php
2
3
use
Sabre\Event\EventEmitter
;
4
5
include __DIR__ .
'/../../vendor/autoload.php'
;
6
7
abstract
class
BenchMark
{
8
9
protected
$startTime
;
10
protected
$iterations
= 10000;
11
protected
$totalTime
;
12
13
function
setUp
() {
14
15
}
16
17
abstract
function
test
();
18
19
function
go
() {
20
21
$this->
setUp
();
22
$this->startTime = microtime(
true
);
23
$this->
test
();
24
$this->totalTime = microtime(
true
) -
$this->startTime
;
25
return
$this->totalTime
;
26
27
}
28
29
}
30
31
class
OneCallBack
extends
BenchMark
{
32
33
protected
$emitter
;
34
protected
$iterations
= 100000;
35
36
function
setUp
() {
37
38
$this->emitter =
new
EventEmitter
();
39
$this->emitter->on(
'foo'
,
function
() {
40
// NOOP
41
});
42
43
}
44
45
function
test
() {
46
47
for
(
$i
= 0;
$i
<
$this->iterations
;
$i
++) {
48
$this->emitter->emit(
'foo'
, []);
49
}
50
51
}
52
53
}
54
55
class
ManyCallBacks
extends
BenchMark
{
56
57
protected
$emitter
;
58
59
function
setUp
() {
60
61
$this->emitter =
new
EventEmitter
();
62
for
(
$i
= 0;
$i
< 100;
$i
++) {
63
$this->emitter->on(
'foo'
,
function
() {
64
// NOOP
65
});
66
}
67
68
}
69
70
function
test
() {
71
72
for
(
$i
= 0;
$i
<
$this->iterations
;
$i
++) {
73
$this->emitter->emit(
'foo'
, []);
74
}
75
76
}
77
78
}
79
80
class
ManyPrioritizedCallBacks
extends
BenchMark
{
81
82
protected
$emitter
;
83
84
function
setUp
() {
85
86
$this->emitter =
new
EventEmitter
();
87
for
(
$i
= 0;
$i
< 100;
$i
++) {
88
$this->emitter->on(
'foo'
,
function
() {
89
}, 1000 -
$i
);
90
}
91
92
}
93
94
function
test
() {
95
96
for
(
$i
= 0;
$i
<
$this->iterations
;
$i
++) {
97
$this->emitter->emit(
'foo'
, []);
98
}
99
100
}
101
102
}
103
104
$tests
= [
105
'OneCallBack'
,
106
'ManyCallBacks'
,
107
'ManyPrioritizedCallBacks'
,
108
];
109
110
foreach
(
$tests
as
$test
) {
111
112
$testObj =
new
$test
();
113
$result
= $testObj->go();
114
echo
$test .
" "
.
$result
.
"\n"
;
115
116
}
ManyCallBacks\$emitter
$emitter
Definition:
bench.php:57
BenchMark\$totalTime
$totalTime
Definition:
bench.php:11
$result
$result
Definition:
CleanUpTest.php:463
ManyPrioritizedCallBacks
Definition:
bench.php:80
ManyCallBacks
Definition:
bench.php:55
BenchMark\go
go()
Definition:
bench.php:19
OneCallBack
Definition:
bench.php:31
OneCallBack\setUp
setUp()
Definition:
bench.php:36
BenchMark
Definition:
bench.php:7
BenchMark\setUp
setUp()
Definition:
bench.php:13
EventEmitter
ManyPrioritizedCallBacks\setUp
setUp()
Definition:
bench.php:84
$tests
$tests
Definition:
bench.php:104
ManyPrioritizedCallBacks\$emitter
$emitter
Definition:
bench.php:82
BenchMark\$startTime
$startTime
Definition:
bench.php:9
BenchMark\$iterations
$iterations
Definition:
bench.php:10
echo
Sabre\Event\EventEmitter
EventEmitter object.
Definition:
EventEmitter.php:14
ManyPrioritizedCallBacks\test
test()
Definition:
bench.php:94
$i
$i
Definition:
disco.tpl.php:19
php
OneCallBack\test
test()
Definition:
bench.php:45
ManyCallBacks\test
test()
Definition:
bench.php:70
ManyCallBacks\setUp
setUp()
Definition:
bench.php:59
BenchMark\test
test()
OneCallBack\$emitter
$emitter
Definition:
bench.php:33
$test
$test
Definition:
Utf8Test.php:84
libs
composer
vendor
sabre
event
tests
benchmark
bench.php
Generated on Thu Jan 30 2025 19:01:29 for ILIAS by
1.8.13 (using
Doxyfile
)