Python and STL efficiency

Fredrik Lundh fredrik at pythonware.com
Mon Aug 21 05:36:37 EDT 2006


Licheng Fang wrote:

> I was using VC++.net and IDLE, respectively. I had expected C++ to be
> way faster. However, while the python code gave the result almost
> instantly, the C++ code took several seconds to run! Can somebody
> explain this to me? Or is there something wrong with my code?

in the Python example, the four strings in your example are shared, so 
you're basically copying 40000 pointers to the list.

in the C++ example, you're creating 40000 string objects.

</F>




More information about the Python-list mailing list