On 6/20/2012 19:53, Dave Angel wrote: > But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently.
There's one more important difference, which is that the JVM does just-in-time (JIT) compilation of bytecode rather than straight interpretation like CPython does. This basically means that as a program is executing, the JVM will sometimes go through what is a more traditional compilation step and translate its bytecode into machine code rather than just interpret it. It will do this for things it discovers are "hot paths" through the program, where spending some extra time up front (while the program is still executing!) for the compilation and optimization steps is worth it in terms of the speedup. In fact, the JVM may transform a given piece of bytecode several times, applying new optimizations as it discovers that some block is not just important, but *really* important. :-) (Where "important" = "executed a lot.") By my understanding, CPython doesn't do any of this; it always executes the same byte code in the same way, and what it does to the bytecode looks more like an interpreter than a JIT compiler. On the other hand, Jython translates Python to Java bytecode and IronPython translates Python to .Net bytecode (MSIL), so if you use one of those implementations of Python, you are getting a JIT. (Nevertheless my understanding is both tend to be slower than CPython? Not sure about that, and don't know by how much or why.) The new kid on the block is PyPy, which is a JIT engine for Python written in Python itself. But the interesting point is that the (very) old view of "compiled or interpreted" breaks down a lot nowadays; it's closer to a continuum: - pure interpreted - compiled to bytecode, which is then interpreted - JIT compiler (almost always this has a bytecode compilation step though theoretically this isn't necessary) - pure compiled I'd say these categories tend to be qualitative "I know it when I see it" rather than hard divisions. Evan > > java has available a "runtime" environment, for those who don't want or > need the compiler. CPython comes with the compiler and the runtime > bundled together. > > Java's classfile remains stable over a number of compiler versions, > while CPython doesn't seem to worry about that. > > Java's classfile has been targeted by a number of other byte code > compilers, including jython. Code from any of those libraries may use > the java libraries. > > With java, one has to explicitly compile the java code, while with > CPython, the runtime logic compiles imported modules if they're not > already compiled. >
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list