Add flag to flush opcache, add flag to run big test on simplerouter

This commit is contained in:
Sky Johnson 2024-09-07 17:01:32 -05:00
parent 86a03bb8ff
commit c85d488e43
3 changed files with 32 additions and 7 deletions

View File

@ -8,6 +8,11 @@
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();

View File

@ -1,5 +1,18 @@
<?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';
@ -17,13 +30,15 @@ sRunIterations(10000, $github);
sRunIterations(100000, $github);
sRunIterations(1000000, $github);
// Big test
SimpleRouter::clearRoutes();
$big = sReadAndAddRoutes('big.txt');
echoTitle("Starting big lookups");
sRunIterations(10000, $big);
sRunIterations(100000, $big);
sRunIterations(1000000, $big);
// 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);
}
function sReadAndAddRoutes(string $file): array
{

View File

@ -8,6 +8,11 @@
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();