by BubRoss · 6y ago · 0 comments
Having said that, the fact it takes 5 seconds is pretty arbitrary—we can't really say it's good or bad unless there is some basis for comparison.
python generate.py > big.py
then this file was executed with Python, that took 5 seconds: time python big.py
and yes, I had no idea what to expect, hence the test.- big.py is almost 15MB
- Running `lua5.3 big.py` takes about 1/6 the time on my Linux VM. (I had to use a big.py only half the size because this VM was too small for the original.)
So Python isn't the fastest at this but I wouldn't call it terrible. Basically all of that time was parsing/compiling, since the time is the same with big.py changed to `def foo(): x0=0 # etc.`
Assuming a fairly naive python interpreter, it involves
- Parsing a million lines of code
- Outputting bytecode for a million lines of code
- Running a million of lines of bytecode, including
- Allocating a million int objects (ints are heap allocated in python)
- Hashing a million identifiers
- Putting those million identifiers into a hashmap, each pointing to the corresponding into object
- Deallocating those million int object
Plus VM/Interpreter startup/shutdown. But we can benchmark that by running an empty python file and it's not significant.
wc big.py
so 5ms is way underestimating the job