Passed
Push — master ( 71b494...4cbbee )
by Anatoly
01:42
created

FastRouteBench::benchFastRouteMatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Sunrise\Http\Router\Benchs;
4
5
use FastRoute\RouteParser\Std as RouteParser;
0 ignored issues
show
Bug introduced by
The type FastRoute\RouteParser\Std was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use FastRoute\DataGenerator\GroupCountBased as DataGenerator;
0 ignored issues
show
Bug introduced by
The type FastRoute\DataGenerator\GroupCountBased was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use FastRoute\Dispatcher\GroupCountBased as Dispatcher;
0 ignored issues
show
Bug introduced by
The type FastRoute\Dispatcher\GroupCountBased was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use FastRoute\RouteCollector;
0 ignored issues
show
Bug introduced by
The type FastRoute\RouteCollector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Sunrise\Http\ServerRequest\ServerRequestFactory;
10
11
/**
12
 * @BeforeMethods({"init"})
13
 */
14
class FastRouteBench
15
{
16
	protected $maxRoutes = 1000;
17
	protected $request;
18
19
	public function init()
20
	{
21
		$uri = \sprintf('/route/%d', $this->maxRoutes);
22
23
		$this->request = (new ServerRequestFactory)
24
		->createServerRequest('GET', $uri);
25
	}
26
27
	/**
28
	 * @Warmup(1)
29
	 * @Revs(10)
30
	 * @Iterations(100)
31
	 */
32
	public function benchFastRouteMatch()
33
	{
34
		$map = new RouteCollector(
35
			new RouteParser(),
36
			new DataGenerator()
37
		);
38
39
		for ($i = 1; $i <= $this->maxRoutes; $i++)
40
		{
41
			$path = \sprintf('/route/%d', $i);
42
			$action = function() {};
43
44
			$map->get($path, $action);
45
		}
46
47
		$dispatcher = new Dispatcher($map->getData());
48
49
		$dispatcher->dispatch(
50
			$this->request->getMethod(),
51
			$this->request->getUri()->getPath()
52
		);
53
	}
54
}
55