Jeremy Sanders a écrit :
> 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?
> 
> It must be the debugging, the compiler or a poor STL implementation. With
> gcc 4 it runs instantly on my computer (using -O2), even with 10x the
> number of values.
> 
> If the problem is that C++ has to make lots of new strings, as other posters
> have suggested, then you could do something like
> 
> const string foo = "What do you know?";
> 
> for (long int i=0; i<10000 ; ++i){
>    a.push_back(foo);
>    ...
> }
> 
> as many C++ implementations use reference counting for identical strings.
> 
> Jeremy
> 

As a matter of fact, do not count on that. Use a vector<string*> just in 
case.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to