dev/tests/trie.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2024-09-07 13:02:52 -05:00
<?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.
*/
require_once 'tools.php';
$r = new TrieRouter();
2024-09-07 13:02:52 -05:00
// Blog test
$blog = readAndAddRoutes('blog.txt', $r);
writeRoutesToFile($r->root, 'storage/trie/blog.txt');
2024-09-07 13:02:52 -05:00
echoTitle("Starting blog lookups");
runIterations(100000, $r, $blog);
runIterations(1000000, $r, $blog);
2024-09-07 13:02:52 -05:00
// Github test
$r->clear();
$github = readAndAddRoutes('github.txt', $r);
writeRoutesToFile($r->root, 'storage/trie/github.txt');
2024-09-07 13:02:52 -05:00
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');
2024-09-07 13:02:52 -05:00
echoTitle("Starting big lookups");
runIterations(10000, $r, $big);
runIterations(100000, $r, $big);
runIterations(1000000, $r, $big);