From 86a03bb8ffb3cf14b1bde9d502c4d12ad9b17d02 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Sat, 7 Sep 2024 16:45:56 -0500 Subject: [PATCH] Update readme with explanation and colors --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 066807f..a68fb8a 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,13 @@ Of course, what good is a router that's slow? We need to be able to lookup route For our benchmarks, which you can find in their respective files in [tests](tests/), we create a single instance of a router, load routes from the `.txt` files, write their respective arrays to `.txt` files in [storage](tests/storage/), then perform three iterations each; 10k, 100k, 1m requests. In these iterations, we pick a random URI from the full list, and have the router perform the lookup on that randomly selected URI. The test fails only if a `404` or `405` is returned. +Below are the results from our most rigorous tests; performing 1 million lookups on 1000 randomized routes with various lengths and parameters. + ### SimpleRouter This is an old project of mine and the first router I ever tried to write. Foundationally it relies on tokenizing an incoming URI and matching it to regex, then looking through the internal routes array. -``` -// big routes +```php Running 1000000 iterations (100000 lookups) M: 1846.2 kb - T: 32.6156370640 s (200000 lookups) M: 1846.2 kb - T: 63.9784071445 s @@ -66,7 +67,7 @@ Interestingly, it has the lowest memory cost of the current iterations, but the This is my first iteration of a PATRICIA trie router in PHP. I don't think it's currently perfect, as we could probably work on storing nodes as bytes rather than strings, but it's a good proof of concept for a tree based mechanism. -``` +```php Running 1000000 iterations (100000 lookups) M: 4718.3 kb - T: 0.0581219196 s (200000 lookups) M: 4718.3 kb - T: 0.1310830116 s @@ -87,7 +88,7 @@ You can immediately see a ***huge*** time difference from SimpleRouter. Response This second iteration is the first to achieve the best of both worlds; lower memory usage and lower time per request! In order to achieve this, we simply split routes into segments and store each segment as a node. This means that there are no extraneous child elements and navigating to an endpoint requires less effort. The [visualization](tests/storage/segment/big.txt) also shows how much simpler the tree is compared to TrieRouter. -``` +```php Running 1000000 iterations (100000 lookups) M: 2891.8 kb - T: 0.0500328541 s (200000 lookups) M: 2891.8 kb - T: 0.0995390415 s @@ -102,4 +103,4 @@ Time: 0.4971950054 s Avg/lookup: 0.0000004973 s ``` -Truly our most impressive show yet. +Truly our most impressive show yet. By simplifying the structure of our tree and only storing what we need, we can achieve pretty incredible results in only 3 MB of RAM.