Java vs Python Benchmarks: Java is faster

Jason Orendorff jason at jorendorff.com
Sun Feb 3 13:28:23 EST 2002


Courageous writes:
> Kragen Sitaker writes:
> >It's true that Java objects all have declared types, but that doesn't
> >save you as much as you'd think;
> 
> While you obviously know what you're talking about and don't need my
> help, I'd just like to add that those folks talking about an optional
> type declaration system for speeding up Python don't seem to have a
> good idea of where the time in Python goes. There are more important
> fish to fry, as I'm sure you realize.

On behalf of all of us that don't know what we're talking about and
do need your help...

I guess I imagine that Python's speed issues are:

 1. Ultra-late binding of, and consequent repetitive lookups of,
    global names, attributes, methods, module members, etc.
    (Of course, unless names like 'int' and 'float' can be bound
    at compile time, optional type declarations are unhelpful.)

    Since many people like this about Python, and many have used it
    in existing code, effort is focused on making lookups cheaper
    (or caching the results) rather than changing the binding
    behavior to require fewer lookups overall.

 2. Nothing ever gets compiled to anything even close to
    machine code.  This is largely because the Python development
    team doesn't have the resources to invest in it.  Clearly
    there's something to gain by moving the huge ceval.c loop/switch
    from runtime to compile time.  No one knows how much.  Clearly
    there's something to lose from the resulting explosion in the
    complexity of the compiler.

 3. Even if you did compile Python to machine code, simple things
    like "x = y + z" would still be packed with object-oriented
    wackiness and much chasing-about of heap pointers.  It doesn't
    compile to simple register code like you want.

 4. Function calls are slow.

 5. Python still has SET_LINENO, which is basically a waste
    of time.  (This is low-hanging fruit, but apparently the
    team is too busy to grab it.)

I believe static typing would help with #1 and #3.

More later.

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list