Re: Python and STL efficiency
Tim N. van der Leeuw wrote:
Alternatively, slow down the Python implementation by making Python
allocate new strings each time round:
a.append('%s' % 'What do you know')
.... for each of your string-appends. But even then, the python-code is
still near-instant.
Cheers,
--Tim
Tim N. van der Leeuw wrote:
Ray wrote:
>
The code still creates a new string - instance each time it tries to
append a const char* to the vector<string.. .
>
You should instead create the string-objects ahead of time, outside of
the loop.
>
Regards,
>
--Tim
Fredrik Lundh wrote:
In which case, Licheng, you should try using the /GF switch. This will
tell Microsoft C++ compiler to pool identical string literals together.
:)
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>
you're basically copying 40000 pointers to the list.
>
in the C++ example, you're creating 40000 string objects.
>
</F>
tell Microsoft C++ compiler to pool identical string literals together.
:)
The code still creates a new string - instance each time it tries to
append a const char* to the vector<string.. .
>
You should instead create the string-objects ahead of time, outside of
the loop.
>
Regards,
>
--Tim
allocate new strings each time round:
a.append('%s' % 'What do you know')
.... for each of your string-appends. But even then, the python-code is
still near-instant.
Cheers,
--Tim
Comment