Python is faster than C

RPM1 rpm1deleteme at direcway.com
Sat Apr 3 21:58:04 EST 2004


"Armin Rigo"  wrote ...
> Hi!
>
> This is a rant against the optimization trend of the Python interpreter.
>
> Sorting a list of 100000 integers in random order takes:
>
> * 0.75 seconds in Python 2.1
> * 0.51 seconds in Python 2.2
> * 0.46 seconds in Python 2.3
>
> Tim Peters did a great job optimizing list.sort().  If I try with a
> simple, non-stable pure Python quicksort implementation, in Python 2.3:
>
> * 4.83 seconds
> * 0.21 seconds with Psyco
>
> First step towards world domination of high-level languages :-)
>
> The reason that Psyco manages to outperform the C implementation is not
> that gcc is a bad compiler (it is about 10 times better than Psyco's).
> The reason is that the C implementation must use a generic '<' operator
> to compare elements, while the Psyco version quickly figures out that it
> can expect to find ints in the list; it still has to check this
> assumption, but this is cheap and then the comparison is done with a
> single machine instruction.
>

I think Psyco is great!  But Python + Psyco does not outperform
C overall.  Try writing a chess program in Python and see how it
performs against C.

Patrick





More information about the Python-list mailing list