/** * Sets up Symfony2 optimized tests */ function setupSymfony2Optimized(Benchmark $benchmark, $routes, $args) { $argString = implode('/', array_map(function ($i) { return "{arg{$i}}"; }, range(1, $args))); $str = $firstStr = $lastStr = ''; $sfRoutes = new \Symfony\Component\Routing\RouteCollection(); for ($i = 0, $str = 'a'; $i < $routes; $i++, $str++) { list($pre, $post) = getRandomParts(); $str = '/' . $pre . '/' . $argString . '/' . $post; if (0 === $i) { $firstStr = str_replace(array('{', '}'), '', $str); } $lastStr = str_replace(array('{', '}'), '', $str); $sfRoutes->add($str, new \Symfony\Component\Routing\Route($str, array('controller' => 'handler' . $i))); } $dumper = new \Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper($sfRoutes); file_put_contents(__DIR__ . '/files/worst-case-sf2.php', $dumper->dump(array('class' => 'WorstCaseSf2UrlMatcher'))); require_once __DIR__ . '/files/worst-case-sf2.php'; $router = new \WorstCaseSf2UrlMatcher(new \Symfony\Component\Routing\RequestContext()); $benchmark->register(sprintf('Symfony2 Dumped - last route (%s routes)', $routes), function () use($router, $lastStr) { $route = $router->match($lastStr); }); $benchmark->register(sprintf('Symfony2 Dumped - unknown route (%s routes)', $routes), function () use($router) { try { $route = $router->match('/not-even-real'); } catch (\Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { } }); }
/** * Sets up Symfony2 optimized tests */ function setupSymfony2Optimized(Benchmark $benchmark, $routes, $args) { $argString = implode('/', array_map(function ($i) { return "{arg{$i}}"; }, range(1, $args))); $str = $firstStr = $lastStr = ''; $sfRoutes = new \Symfony\Component\Routing\RouteCollection(); for ($i = 0, $str = 'a'; $i < $routes; $i++, $str++) { list($pre, $post) = getRandomParts(); $str = '/' . $pre . '/' . $argString . '/' . $post; if (0 === $i) { $firstStr = str_replace(array('{', '}'), '', $str); } $lastStr = str_replace(array('{', '}'), '', $str); $sfRoutes->add($str, new \Symfony\Component\Routing\Route($str, array('controller' => 'handler' . $i))); } $dumper = new \Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper($sfRoutes); file_put_contents(__DIR__ . '/files/first-route-sf2.php', $dumper->dump(array('class' => 'FirstRouteSf2UrlMatcher'))); require_once __DIR__ . '/files/first-route-sf2.php'; $router = new \FirstRouteSf2UrlMatcher(new \Symfony\Component\Routing\RequestContext()); $benchmark->register('Symfony2 Dumped - first route', function () use($router, $firstStr) { $route = $router->match($firstStr); }); }