-
Notifications
You must be signed in to change notification settings - Fork 4
/
dispatch.php
103 lines (79 loc) · 2.47 KB
/
dispatch.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
<?php
// http://github.com/c9s/php-SimpleBench.git
require 'SimpleBench/Task.php';
require 'SimpleBench/Utils.php';
require 'SimpleBench/ComparisonMatrix.php';
require 'SimpleBench/MatrixWriter/Writer.php';
require 'SimpleBench/MatrixWriter/JsonWriter.php';
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench.php';
// requirement from symfon
require 'symfony/vendor/autoload.php';
require 'pux/pux/vendor/autoload.php';
require 'klein/vendor/autoload.php';
require 'ham/ham/ham/ham.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Pux\Mux;
$bench = new SimpleBench;
$bench->setN( 10000 );
// plain php dispatch function
$phparray = array(
'/hello' => array( 'hello' )
);
function phparray_dispatch($path) {
global $phparray;
if ( isset($phparray[$path]) ) {
return $phparray[$path];
}
foreach( $phparray as $pattern => $route ) {
if ( preg_match('#' . $pattern . '#', $path) ) {
return $route;
}
}
}
$bench->iterate( 'php array' , function() use ($phparray) {
$route = phparray_dispatch('/hello');
});
$mux = require 'pux/hello_mux.php';
$bench->iterate( 'pux' , function() use ($mux) {
$route = $mux->match('/hello');
});
// klein
$klein = new \Klein\Klein();
$klein->respond('GET', '/hello', function () {
return 'hello';
});
$bench->iterate( 'klein' , function() use ($klein) {
$klein->dispatch();
});
// ham
$_SERVER['REQUEST_URI'] = '/hello';
$ham = new Ham('example');
$ham->route('/hello', function($ham) {
});
$bench->iterate( 'ham' , function() use ($ham) {
$ham->run();
});
// aura
$aura = require 'aura/aura/scripts/instance.php';
$aura->add('hello', '/hello');
$bench->iterate( 'aura' , function() use ($aura) {
$route = $aura->match('/hello', $_SERVER);
});
// Symfony
$routes = new RouteCollection();
$routes->add('hello', new Route('/hello', array('controller' => 'foo', 'action' => 'bar' )));
$bench->iterate( 'symfony/routing' , function() use ($routes) {
$context = new RequestContext();
$context->fromRequest(Request::createFromGlobals());
$matcher = new UrlMatcher($routes, $context);
$route = $matcher->match('/hello');
});
$result = $bench->compare();
echo $result->output('console');