Licheng Fang wrote: > Hi, I'm learning STL and I wrote some simple code to compare the > efficiency of python and STL.
> 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? Just a guess: immutable strings might be Python's advantage. Due to your "benchmark"'s simplicity you end up with 10000 string instances in C++ and just four str-s (and a lot of pointers) in Python. What happens if you replace 'string' with 'const char *' in C++ ? (Note that this modification is a bit unfair to Python as it would not detect equal strings in different memory locations) Peter -- http://mail.python.org/mailman/listinfo/python-list