3 ms·
Yeah, conceptually for smaller sets a DFA should easily meet or beat perfect hashing for the reason you describe. But because of pipelining, branch prediction,
by wahern 8y ago
Yeah, conceptually for smaller sets a DFA should easily meet or beat perfect hashing for the reason you describe.
But because of pipelining, branch prediction, etc, it depends on the details of how the generated parser scans the input stream. A simple hash function is more likely to execute in a tight loop with minimal data dependencies because it's more natural to code it that way; it might be able to consume the stream faster even if performing more work simply because of how it slices the work. I'm not positive, but AFAICT Flex only generates table-driven machines, so at the very minimum the scanner is already handicapped. A tiny table that fits in cache might not be much of a handicap, but I'd be surprised if Flex does an especially good job of that. Any why would it--it's designed to work in tandem with Bison to solve more complex problems, plus it's hemmed in by having to support historical program structures and interfaces, such as liberal use of functions and function pointers for composition.