routes, 'storage/segment/blog.txt'); echoTitle("Starting blog lookups"); runIterations(10000, $r, $blog); runIterations(100000, $r, $blog); runIterations(1000000, $r, $blog); unset($blog); // Github lookups $r->clear(); $github = readAndAddRoutes('github.txt', $r); writeRoutesToFile($r->routes, 'storage/segment/github.txt'); echoTitle("Starting github lookups"); runIterations(10000, $r, $github); runIterations(100000, $r, $github); runIterations(1000000, $r, $github); unset($github); // Big lookups $r->clear(); $big = readAndAddRoutes('big.txt', $r); writeRoutesToFile($r->routes, 'storage/segment/big.txt'); echoTitle("Starting big lookups"); runIterations(10000, $r, $big); runIterations(100000, $r, $big); runIterations(1000000, $r, $big); unset($big); // Parameter testing $r->clear(); echoTitle("Testing parameters"); $routes = [ ['GET', '/blog/:id', function($id) { echo $id."\n"; }], ['GET', '/blog/:id/:slug', function($id, $slug) { echo $id . ' - ' . $slug."\n"; }], ['GET', '/blog/:id/:slug/:page', function($id, $slug, $page) { echo $id . ' - ' . $slug . ' - ' . $page."\n"; }], ['GET', '/blog/:id/:slug/:page/:extra', function($id, $slug, $page, $extra) { echo $id . ' - ' . $slug . ' - ' . $page . ' - ' . $extra."\n"; }], ]; foreach ($routes as $route) { [$method, $path, $handler] = $route; $r->add($method, $path, $handler); } for ($i = 0; $i < 10; $i++) { [$method, $uri] = $routes[array_rand($routes)]; // Generate some random parameters $uri = str_replace(':id', rand(1, 100), $uri); $uri = str_replace(':slug', 'slug-' . rand(1, 100), $uri); $uri = str_replace(':page', rand(1, 100), $uri); $uri = str_replace(':extra', 'extra-' . rand(1, 100), $uri); $res = $r->lookup($method, $uri); if ($res['code'] !== 200) { echo "Failed to handle request for $uri - $res\n"; exit(1); } $res['handler'](...$res['params']); }