-
Notifications
You must be signed in to change notification settings - Fork 7
/
benchmark-all.php
110 lines (87 loc) · 2.58 KB
/
benchmark-all.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
<?php
// rough benchmark comparing the time required to bootstrap and
// resolve the dependencies in a simple test-case.
use mindplay\benchpress\Benchmark;
require __DIR__ . '/header.php';
$bench = new Benchmark();
$unbox_configuration = function () {
$setup = require __DIR__ . '/bootstrap-unbox.php';
$container = $setup();
};
$phpdi_configuration = function () {
$setup = require __DIR__ . '/bootstrap-php-di.php';
$container = $setup();
};
$phpdi_compiled_configuration = function() {
$setup = require __DIR__ . '/bootstrap-php-di.php';
$container = $setup(compiled: true);
};
$pimple_configuration = function () {
$setup = require __DIR__ . '/bootstrap-pimple.php';
$container = $setup();
};
$bench->add(
'unbox: configuration',
$unbox_configuration
);
$bench->add(
'php-di: configuration',
$phpdi_configuration
);
$bench->add(
'php-di: configuration [compiled]',
$phpdi_compiled_configuration
);
$bench->add(
'pimple: configuration',
$pimple_configuration
);
$bench->run();
foreach ([1,3,5,10] as $num) {
$bench = new Benchmark();
$bench->add(
"unbox: {$num} repeated resolutions",
function () use ($num) {
$setup = require __DIR__ . '/bootstrap-unbox.php';
$container = $setup();
for ($i = 0; $i < $num; $i++) {
$cache = $container->get(UserRepository::class);
}
},
$unbox_configuration
);
$bench->add(
"php-di: {$num} repeated resolutions",
function () use ($num) {
$setup = require __DIR__ . '/bootstrap-php-di.php';
$container = $setup();
for ($i = 0; $i < $num; $i++) {
$cache = $container->get(UserRepository::class);
}
},
$phpdi_configuration
);
$bench->add(
"php-di: {$num} repeated resolutions [compiled]",
function () use ($num) {
$setup = require __DIR__ . '/bootstrap-php-di.php';
$container = $setup(compiled: true);
for ($i = 0; $i < $num; $i++) {
$cache = $container->get(UserRepository::class);
}
},
$phpdi_configuration
);
$bench->add(
"pimple: {$num} repeated resolutions",
function () use ($num) {
$setup = require __DIR__ . '/bootstrap-pimple.php';
$container = $setup();
for ($i = 0; $i < $num; $i++) {
$cache = $container->get(UserRepository::class);
}
},
$pimple_configuration
);
$bench->run();
}