nikic/FastRoute — pull request #18 by psychoticmeow (2014-05-08 16:03:04+00:00)
Title: A new DataGenerator/Dispatcher approach involving lots of tab characters

I'm making this pull request not because this method is better than what's already implemented, because *it isn't*, but because I wanted to share the code and see if it could be improved further.

The basic idea is that each route expression will match the appropriate amount of tab characters following its expression. So the expression for handler0 would match one tab character, and the expression for handler1 would match two tab characters, and so on.

The obvious problem with this, at least to me, is that we have to append a bunch of tab characters to the end of the URI, making it longer in length and time to match.

But it works! Here are some benchmarks:

| Benchmark | GroupCountBased | GroupPosBased | CharCountBased |
|-----------------|------------------|------------------|------------------|
| First route | 0.255s (19 runs) | 0.238s (21 runs) | 0.311s (16 runs) |
| Last route | 0.828s (6 runs) | 0.814s (6 runs) | 0.793s (6 runs) |
| Unknown route | 0.641s (7 runs) | 0.610s (8 runs) | 0.548s (9 runs) |
| Combined routes | 1.712s (8 runs) | 1.655s (9 runs) | 1.647s (9 runs) |

The script to run the benchmark can be found here: https://gist.github.com/psychoticmeow/d94616529359a8a9ee5d