compiled Jython vs. CPython

Ype Kingma ykingma at accessforall.nl
Mon Apr 22 16:57:28 EDT 2002


Jonathan,

"Jonathan P." wrote:
> 
> Has anyone out there tried to compare the
> speed of a jythonc-compiled app to that of a
> CPython one?

This is the best I could find (from June 2001,
I hope someone has more recent info):

http://www.geocrawler.com/archives/3/7018/2001/6/0/6016132/

and the benchmarks comparing Jython+JIT to CPython
are mostly in favour of CPython.

>
> It is possible that if such an app does not
> depend on a runtime interpreter and is run
> by a JIT-JVM that it might give better performance
> than one which runs interpreted (i.e. CPython).

It's possible to compile using CPython to an executable,
and it's possible to compile using jythonc to a jar
including everything needed for execution in a JVM.
However, due to the dynamic nature of python
the compilation results need to include large
parts of the interpreter itself, eg. consider
how one would compile:

exec someStringWithPythonCode

There is no choice for this: here an interpreter has
to be called even from compiled code.

> JIT-compilation techniques have come a long way
> and in fact most benchmarks I've seen show that
> JIT-compiled Java code run faster than
> statically-compiled ones by a substantial
> margin!

An advantage of jython is that it profits from
speedups of the JVM's. Since Java is more widespread
than CPython, there is in general more interest in
speeding up JVM's than in speeding up the CPython
byte code interpreter.

> Could jythonc be *the* Python compiler we wish
> we had?

In both CPython and Jython all python code is compiled
on the fly to byte code before being executed. For imported
modules this byte code is also saved.

Jythonc is used to compile python code to java classes
that can be used by other java code. It allows eg.
to define java method signatures for python methods
and to define a java package for the generated java class.
This is needed for calling jython from java code.
AFAIK the method/function body code (ie. not dependent
on the method signature) generated by jythonc is
the same as the method body code generated on the fly.

However compilation to byte code is only one factor
that determines execution speed.
The speed of byte code execution is another factor,
and this is where Java's JIT helps a lot, but AFAIK
currently not enough to wish we all had java bytecodes
instead of CPython bytecodes.


Regards,
Ype

-- 
email at xs4all.nl



More information about the Python-list mailing list