Created
January 9, 2017 01:18
-
-
Save markstory/31d4ca1baffb01e9638a5f00bbdbfad7 to your computer and use it in GitHub Desktop.
Routing test file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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