forked from jails/php-router-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.php
executable file
·130 lines (116 loc) · 3.66 KB
/
benchmark.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
#!/usr/bin/env php
<?php
$composer = include './vendor/autoload.php';
include 'RouteGenerator.php';
$composer->add('lithium\\', __DIR__ . '/libraries');
use Lead\Box\Box;
use Lead\Dir\Dir;
use Lead\Benchmark\Benchmark;
$adapters = Dir::scan('./adapters', [
'type' => 'file',
'skipDots' => true
]);
foreach ($adapters as $file) {
if (file_exists($file)) {
include $file;
}
}
$box = box('benchmark', new Box());
$modes = [
'With Routes Supporting All HTTP Methods' => false,
'With Routes Supporting Only A Single HTTP Methods' => true
];
$benchmarks = [
[
'filename' => 'path',
'nbRoutes' => 100,
'forms' => [
'Best Case (path)' => [
'strategy' => function() {
return function(&$ids, &$method, $host = '*') {
return reset($ids[$host][$method]);
};
}
],
'Average Case (path)' => [
'strategy' => function() {
return function(&$ids, &$method, $host = '*') {
return $ids[$host][$method][floor(count($ids[$host][$method]) / 2)];
};
}
],
'Worst Case (path)' => [
'strategy' => function() {
return function(&$ids, &$method, $host = '*') {
return end($ids[$host][$method]);
};
}
]
]
],
/*[
'filename' => 'subdomain',
'nbRoutes' => 10,
'forms' => [
'Best Case (sub-domain)' => [
'nbHosts' => function() {
return 10;
},
'strategy' => function() {
return function(&$ids, &$method, $host) {
return reset($ids[$host][$method]);
};
}
],
'Average Case (sub-domain)' => [
'nbHosts' => function() {
return 10;
},
'strategy' => function() {
return function(&$ids, &$method, $host) {
return $ids[$host][$method][floor(count($ids[$host][$method]) / 2)];
};
}
],
'Worst Case (sub-domain)' => [
'nbHosts' => function() {
return 10;
},
'strategy' => function() {
return function(&$ids, &$method, $host) {
return end($ids[$host][$method]);
};
}
]
]
]*/
];
$dirs = Dir::scan('./benchmarks', [
'type' => 'dir',
'skipDots' => true
]);
foreach ($modes as $title => $isolated) {
echo Benchmark::title($title, '#');
$box->service('isolated', $isolated);
foreach ($benchmarks as $bench) {
$name = $bench['filename'];
foreach ($bench['forms'] as $title => $variables) {
foreach ($variables as $key => $value) {
$box->service($key, $value);
}
$benchmark = new Benchmark();
echo Benchmark::title($title);
$benchmark->repeat(10);
foreach ($dirs as $dir) {
$path = $dir . DIRECTORY_SEPARATOR . $name . ".php";
if (file_exists($path)) {
$generator = new RouteGenerator();
$generator->nbRoutes($bench['nbRoutes']);
include $path;
}
gc_collect_cycles();
}
echo $benchmark->chart();
}
}
}