On Sun, 2009-04-19 at 18:11 +0200, Ryniek90 wrote: > Hi. > > Standard Python interpreter's implementation is written in C language. C > code while compilation, is compilled into machine code (the fastest > code). Python code is compiled into into byte-code which is also some > sort of fast machine code. So why Python interpreter is slower than Java > VM? Being written in C and compilled into machine code, it should be as > fast as C/Asm code. > What's wrong with that?
I can't remember Java properly, but... Firstly, speed will depend on what you're writing. I dont' actually know how much slower python is, but I'm sure there are some things that run faster in python. for example, the program: #!/usr/bin/python print "Hello World" is almost certainly faster in python than Java, as the JVM takes much longer to start up. But basically for the actual code execution speed, it's the Virtual machine: Dynamic typing ... is great for productivity, and a great language feature, but it does mean that most operations in the virtual machine have to be wrapped in some kind of type-checking. That adds more and more operations to the work that has to be done to run python code. Just in Time ... is used in the Java VM but not in the standard python VM. It can significantly optimise performance though. There are various people working on adding a JIT to python - I'm most interested in pypy, here's a basic article explaining their current target of adding a tracing JIT ( I believe it's working on a small subset of python): http://morepypy.blogspot.com/2009/03/applying-tracing-jit-to-interpreter.html (Just spotted that there was a new pypy release yesterday if people haven't noticed) You'll also probably notice that many of python's types (list, dict, etc.) might be slower for small sizes than Java's are - that's because they have been optimised to perform efficiently at any size, at the expense of being slightly less efficient than they could be for small sizes) Tim Wintle -- http://mail.python.org/mailman/listinfo/python-list