开发者

Run-time compilation: How is it possible that this isn't a performance hit?

I've heard that some types of runtime compilation aren't a performance hit. The official Python documentation asserts that running a .pyc file is no faster than .py. (I can't find the link right now.) How is this possible? Doesn't it take time to generate bytecod开发者_开发问答e from the .py?

What about languages like PHP? Isn't it necessary to compile them on every execution? Why would you want this? It seems like a waste of time if the same script will be run many times.


Without the context of the actual document you were reading, it's impossible to say for sure, but I think you might be misunderstanding what is meant by "performance".

The application starts slower if it has to be compiled to bytecode on startup, but it doesn't run slower. Without qualification, someone talking about "performance" is almost never referring to start-up time.


Python checks for a .pyc file and when it does not exist, or if it is out of date it will recreate the bytecode from the .py file.

If the filesystem is not writeable, this step still happens in RAM before the program runs.

So Python is never interpreting code line by line as it runs the program.

The upshot is that if the .pyc file exists and is current, you program will start running a tiny bit sooner, but the execution speed will be the same

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜