Python and STL efficiency

could.net at gmail.com could.net at gmail.com
Tue Aug 22 22:16:29 EDT 2006


That's to say,
python is still much faster?

I am a c++ newbie but I think c++ should be faster here.
Maybe someone can post this to the c++ maillist and they will tell how
to accelerate it.
Tim N. van der Leeuw wrote:
> Mc Osten wrote:
> > Fredrik Lundh <fredrik at pythonware.com> wrote:
> >
> > > Python's memory allocator is also quite fast, compared to most generic
> > > allocators...
> >
> > In fact also in the two "slow" versions Python outperforms C++.
> > I didn't notice it in the first place.
> >
> > --
> > blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
> > site:  http://www.akropolix.net/rik0/      | tenetevi riso e
> > forum: http://www.akropolix.net/forum/     | bacchette per voi.
>
> Well, I guess I'm getting really obsessed with this. But anyways. I
> installed MinGW on my Windows-XP (sp2) laptop. It is g++ version 3.4.5
> -- ancient, yes, but on windows it's the latest available.
>
> I compiled Mc Osten's C++ program (tweaked the output a little) and ran
> it; ran his version of the python code too.
> Oh boy; yes indeed the slow python is faster than the fast C++
> version... Must be something really awful happening in the STL
> implementation that comes with GCC 3.4!
>
> Here's the output from my console:
>
> LeeuwT at nlshl-leeuwt ~/My Documents/Python
> $ g++ -O3 -march=pentium-m -o SpeedTest SpeedTest.cpp
>
> LeeuwT at nlshl-leeuwt ~/My Documents/Python
> $ ./SpeedTest.py
> Begin Test
> Number of unique string objects: 4
> so long...
> What do you know
> fool
> chicken crosses road
> Number of unique string objects: 40000
> so long...
> What do you know
> fool
> chicken crosses road
> Fast - Elapsed: 0.037574 seconds
> Slow - Elapsed: 0.081520 seconds
>
> LeeuwT at nlshl-leeuwt ~/My Documents/Python
> $ ./SpeedTest.exe
> Begin Test
> What do you know?
> chicken crosses road
> fool
> so long...
> What do you know?
> chicken crosses road
> fool
> so long...
> Fast - Elapsed: 2.089 seconds
> Slow - Elapsed: 6.303 seconds
>
> LeeuwT at nlshl-leeuwt ~/My Documents/Python
> 
> 
> Cheers,
> 
> --Tim




More information about the Python-list mailing list