by theseoafs · 12y ago · 0 comments
C++ has had this operator overloaded for strings for decades.
With regard to the size of compiled executables, I can't really say much except "that's not what it's made for". If you need to ship compiled executables to people, Python is an extraordinarily inappropriate choice; stick with C++.
Operator overloading is something, that belongs to the 'pro' skill-set of C++ developers and done wrong, can lead to many problems.
In Python it is much easier to overwrite the behavior of such standard methods and the language core can be learned in about 1/4 of the time you need to learn in C++ to just know the basics (C core, C++ object basics, Operator overloading, standard library basics like the string class, ...) -- in Python you get the power with much less learning effort and without the technical troubles.
Here's the code (Visual Studio 2010):
#include <string>
#include <time.h>
char buf[64], buf2[64];
clock_t start = clock();
for(i = 0; i < 100000; i++)
{ _snprintf(buf, sizeof(buf), "%d", i);
_snprintf(buf2, sizeof(buf2), "%d", i * i);
#if defined FAST
strcat(buf, buf2);
#else
std::string s1 = buf;
std::string s2 = buf2;
std::string s3 = s1 + s2;
#endif
}
_snprintf(buf, sizeof(buf), "%.4f\n", (float)(clock() - start) / (float)CLK_TCK);
OutputDebugString(buf);C++ is all about low-cost abstractions. Any speed difference between the C++ way and the C way should be very small, and the C++ way is safer. Use std::string (and std::vector and all the rest) unless you have a very good reason not too, and then you should probably just write your own custom implementation. Reverting to the C way is just asking for issues.
I'm all for using abstractions and working smarter, but why pay such a performance penalty?