Closed UnrealQuester closed 9 years ago
Turns out using a different parsing library gets the runtime down very close to nom. https://github.com/Codas/nom_benchmarks/tree/dev. Might be better to just swap that in entirely.
Thanks for your help! Multiple implementations are fine, it's good to compare everything. I guess at one point, this project will turn into "parser benchmarks" instead of just "nom benchmarks" :smile:
The parser using attoparsec is using choice to parse the box type. This basically reads 4 bytes and compares them against a string. If the comparison fails, it has to go back and read 4 bytes again for the next match. What can be done instead is first reading the box name and then checking all box types. Because we do not have to rely on backtracking we get noticeably better performance. Before:
After:
I am not sure if the hammer and nom versions do backtracking. It is not really needed in this case. If they do, then the comparison is fair and I apologize for wasting your time.