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

SunriseBench::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sunrise\Http\Router\Benchs;
4
5
use Sunrise\Http\Router\RouteCollection;
6
use Sunrise\Http\Router\Router;
7
use Sunrise\Http\ServerRequest\ServerRequestFactory;
8
9
/**
10
 * @BeforeMethods({"init"})
11
 */
12
class SunriseBench
13
{
14
	protected $maxRoutes = 1000;
15
	protected $request;
16
17
	public function init()
18
	{
19
		$uri = \sprintf('/route/%d', $this->maxRoutes);
20
21
		$this->request = (new ServerRequestFactory)
22
		->createServerRequest('GET', $uri);
23
	}
24
25
	/**
26
	 * @Warmup(1)
27
	 * @Revs(10)
28
	 * @Iterations(100)
29
	 */
30
	public function benchSunriseMatch()
31
	{
32
		$map = new RouteCollection();
33
34
		for ($i = 1; $i <= $this->maxRoutes; $i++)
35
		{
36
			$id = \sprintf('route:%d', $i);
37
38
			// Усложним себе задачу...
39
			$map->get($id, '/route/{i}')->addPattern('i', "{$i}");
40
		}
41
42
		$router = new Router($map);
43
		$router->match($this->request);
44
	}
45
}
46