Skip to content

Instantly share code, notes, and snippets.

@markstory
Created January 9, 2017 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markstory/31d4ca1baffb01e9638a5f00bbdbfad7 to your computer and use it in GitHub Desktop.
Save markstory/31d4ca1baffb01e9638a5f00bbdbfad7 to your computer and use it in GitHub Desktop.
Routing test file
<?php
require './vendor/autoload.php';
use Cake\Core\Configure;
use Cake\Http\ServerRequest;
use Cake\Routing\Router;
// Setup
define('CONFIG', __DIR__ . '/tests/test_app/config/');
Configure::write('App', [
'base' => '',
'webroot' => '/'
]);
Router::reload();
Router::scope('/', function($routes) {
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'view']);
$routes->connect('/bookmarks', ['controller' => 'Bookmarks', 'action' => 'index']);
$routes->connect('/bookmarks/:action/*', ['controller' => 'Bookmarks']);
});
$loops = 10000;
// Create request and run routes.
$request = new ServerRequest([
'environment' => [
'HTTP_HOST' => 'cakephp.org',
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/bookmarks/view/10'
]
]);
Router::pushRequest($request);
$start = microtime(true);
for ($i = 0; $i <= $loops; $i++) {
$r = Router::parse($request->getUri()->getPath(), $request->getMethod());
}
$end = microtime(true);
printf("Router::parse() %f\n\n", $end - $start);
$start = microtime(true);
for ($i = 0; $i <= $loops; $i++) {
$r = Router::parseRequest($request);
}
$end = microtime(true);
printf("Router::parseRequest() %f\n\n", $end - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment