-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.php
83 lines (58 loc) · 2.22 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
<?php
/**
* This file is part of the Makise-Co Framework
*
* World line: 0.571024a
* (c) Dmitry K. <[email protected]>
*/
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
require_once 'helpers/route-collector-native-call.php';
use DI\Container;
use MakiseCo\Http\Router\RouteCollectorFactory;
$response = new \GuzzleHttp\Psr7\Response(200, [], 'Hello World');
$responseHandler = static function () use ($response): \Psr\Http\Message\ResponseInterface {
return $response;
};
$collector = (new RouteCollectorFactory())->create(
new Container(),
);
$collector->get('/', $responseHandler);
$collector->get('/admin/users', $responseHandler);
$collector->get('/admin/users/{id:\d+}', $responseHandler);
$iterCount = 1_000_000;
$requestRoot = new \GuzzleHttp\Psr7\ServerRequest('GET', '/');
$requestAdminUsers = new \GuzzleHttp\Psr7\ServerRequest('GET', '/admin/users');
$requestAdminUsersGet = new \GuzzleHttp\Psr7\ServerRequest('GET', '/admin/users/1');
$router = $collector->getRouter();
$start = microtime(true);
for ($i = 0; $i < $iterCount; $i++) {
$router->handle($requestRoot);
$router->handle($requestAdminUsers);
$router->handle($requestAdminUsersGet);
}
$end = microtime(true);
$time = $end - $start;
printf("php-di/invoker:\n");
printf("Time took: %.8f secs (%.8f secs per request)\n\n", $time, $time / ($iterCount * 3));
$collector = getNativeCallRouteCollector(
new Container(),
);
$collector->get('/', $responseHandler);
$collector->get('/admin/users', $responseHandler);
$collector->get('/admin/users/{id:\d+}', $responseHandler);
$iterCount = 1_000_000;
$requestRoot = new \GuzzleHttp\Psr7\ServerRequest('GET', '/');
$requestAdminUsers = new \GuzzleHttp\Psr7\ServerRequest('GET', '/admin/users');
$requestAdminUsersGet = new \GuzzleHttp\Psr7\ServerRequest('GET', '/admin/users/1');
$router = $collector->getRouter();
$start = microtime(true);
for ($i = 0; $i < $iterCount; $i++) {
$router->handle($requestRoot);
$router->handle($requestAdminUsers);
$router->handle($requestAdminUsersGet);
}
$end = microtime(true);
$time = $end - $start;
printf("native invoker (without DI):\n");
printf("Time took: %.8f secs (%.8f secs per request)\n\n", $time, $time / ($iterCount * 3));