Router/tests/trie.php

44 lines
1.3 KiB
PHP

<?php
/*
This test file puts the PATRICIA trie 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';
$r = new TrieRouter();
// Blog test
$blog = readAndAddRoutes('blog.txt', $r);
writeRoutesToFile($r->root, 'storage/trie/blog.txt');
echoTitle("Starting blog lookups");
runIterations(100000, $r, $blog);
runIterations(1000000, $r, $blog);
// Github test
$r->clear();
$github = readAndAddRoutes('github.txt', $r);
writeRoutesToFile($r->root, 'storage/trie/github.txt');
echoTitle("Starting github lookups");
runIterations(10000, $r, $github);
runIterations(100000, $r, $github);
runIterations(1000000, $r, $github);
// Big test
$r->clear();
$big = readAndAddRoutes('big.txt', $r);
writeRoutesToFile($r->root, 'storage/trie/big.txt');
echoTitle("Starting big lookups");
runIterations(10000, $r, $big);
runIterations(100000, $r, $big);
runIterations(1000000, $r, $big);