M8R-n7vorv at M8R-n7vorv at
Thu Aug 7 11:52:33 CEST 2008

On Aug 7, 6:38 am, bearophileH... at wrote:
> On Aug 7, 2:05 am, "Jack" <nos... at> wrote:
> > I know one benchmark doesn't mean much but it's still disappointing to see
> > Python as one of the slowest languages in the test:
> >
> That Python code is bad, it contains range() instead of xrange, the
> big loop is in the main code instead of inside a function, uses ==
> None, etc. That person can try this (with Psyco), I have changed very
> little, the code is essentially the same:

Yes, this was pointed out in the comments. I had updated the code to
xrange and is and is not instead of range, == and !=, which is how
benchmark got updated to 192 microseconds. Moving the main loop into
a main function resulted in no discernible difference.

Testing with psyco resulted in a time of 33 microseconds per

> On my PC the Java version takes 1.17 us, while the C++ version (with
> MinGW 4.2.1) takes 9.8 us.
> A raw D translation needs 14.34 us, while a cleaned up (that uses
> structs, no getters/setters) needs 4.67 us.
> I don't know why my C++ is so much slow (doing the same things to the C
> ++ version doesn't change its running time much).
> Bye,
> bearophile

Wonder what optimisation level you are using. I to the best of my
recollection used -O3


More information about the Python-list mailing list