Compare commits
No commits in common. "5277acfe395a63d72cb2e9fecd36cb49974911d4" and "86a03bb8ffb3cf14b1bde9d502c4d12ad9b17d02" have entirely different histories.
5277acfe39
...
86a03bb8ff
|
@ -8,11 +8,6 @@
|
|||
The requests are randomly picked from the array of routes.
|
||||
*/
|
||||
|
||||
// if there's a flag, reset the opcache
|
||||
if (in_array('-f', $argv)) {
|
||||
opcache_reset();
|
||||
}
|
||||
|
||||
require_once 'tools.php';
|
||||
|
||||
$r = new SegmentRouter();
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
This test file puts the SimpleRouter to the test by running a million lookups on a handful
|
||||
of routes. The routes are read from two files, blog.txt and github.txt, and added to two separate
|
||||
routers and two separate arrays. The lookups are then run in two separate loops, one for each router.
|
||||
Each lookup is timed and the memory usage is also printed out at regular intervals.
|
||||
The requests are randomly picked from the array of routes.
|
||||
*/
|
||||
|
||||
// if there's a flag, reset the opcache
|
||||
if (in_array('-f', $argv)) {
|
||||
opcache_reset();
|
||||
}
|
||||
|
||||
require_once 'tools.php';
|
||||
require_once __DIR__ . '/../SimpleRouter.php';
|
||||
|
||||
|
@ -30,15 +17,13 @@ sRunIterations(10000, $github);
|
|||
sRunIterations(100000, $github);
|
||||
sRunIterations(1000000, $github);
|
||||
|
||||
// Big test; since simplerouter is so much slower, we'll only run the big test if the -b flag is passed
|
||||
if (in_array('-b', $argv)) {
|
||||
SimpleRouter::clearRoutes();
|
||||
$big = sReadAndAddRoutes('big.txt');
|
||||
echoTitle("Starting big lookups");
|
||||
sRunIterations(10000, $big);
|
||||
sRunIterations(100000, $big);
|
||||
sRunIterations(1000000, $big);
|
||||
}
|
||||
// Big test
|
||||
SimpleRouter::clearRoutes();
|
||||
$big = sReadAndAddRoutes('big.txt');
|
||||
echoTitle("Starting big lookups");
|
||||
sRunIterations(10000, $big);
|
||||
sRunIterations(100000, $big);
|
||||
sRunIterations(1000000, $big);
|
||||
|
||||
function sReadAndAddRoutes(string $file): array
|
||||
{
|
||||
|
|
|
@ -106,18 +106,13 @@ function runIterations(int $iterations, $r, array $routes) {
|
|||
$interval = $iterations / 10;
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
// pick a random route from the array
|
||||
[$method, $path] = $routes[array_rand($routes)];
|
||||
// replace all :params/ with random values
|
||||
$uri = preg_replace_callback('/:(\w+)/', function($matches) {
|
||||
return rand(1, 100);
|
||||
}, $path);
|
||||
$start2 = microtime(true);
|
||||
[$method, $uri] = $routes[array_rand($routes)];
|
||||
$res = $r->lookup($method, $uri);
|
||||
if ($res === 404 || $res === 405) {
|
||||
echo Color::red("Failed to handle request.\n$method $res\n"."├─ URI: $uri\n├─ Path: $path\n");
|
||||
echo Color::red("Failed to handle request for $uri - $res\n");
|
||||
exit(1);
|
||||
}
|
||||
if ($i !== 0 && $i % ($interval) === 0) echoMemoryAndTime($i, $start2);
|
||||
if ($i !== 0 && $i % ($interval) === 0) echoMemoryAndTime($i, $start);
|
||||
}
|
||||
echo "Time: " . Color::cyan(number_format(microtime(true) - $start, 10) . " s\n");
|
||||
// echo the average time per request
|
||||
|
|
|
@ -8,11 +8,6 @@
|
|||
The requests are randomly picked from the array of routes.
|
||||
*/
|
||||
|
||||
// if there's a flag, reset the opcache
|
||||
if (in_array('-f', $argv)) {
|
||||
opcache_reset();
|
||||
}
|
||||
|
||||
require_once 'tools.php';
|
||||
|
||||
$r = new TrieRouter();
|
||||
|
|
Loading…
Reference in New Issue
Block a user