The Speed of Python, Ruby, and Lua's Parsers
I’ve run into some cases lately where loading a lot of generated code
in Python takes a lot of time. When I profiled my test case the
hotspot seemed to be the parser itself – that is, Python’s parser
that parses .py
source files.
I realized that I had no idea how fast the parsers for some of these languages are. As someone who is interested in parsers, this piqued my interest. I was particularly interested to see how much precompiling would help.
To satisfy my curiosity, I wrote a quick little benchmark that tries to get some rough numbers on this.
These are the results I got on my machine:
My takeaways from this are:
- There is a surprising amount of variation here. Python’s parser probably has a lot of room for optimization. But the fact that precompiling is available probably reduces the demand for this considerably.
- Precompiling helps a lot.
- Lua continues to impress.