|
|
|
|
|
by 30thElement
4320 days ago
|
|
Well of course you're getting a speed difference, look at how much extra work you're doing in the std::string code! The char[64]s are allocated once but you reallocate the std::strings every time. By pulling the declaration of s1, s2, and s3 to the top, I'm getting equivalent speed (g++ 4.4.7 with -g, 0.02s each time, clock() isn't any more accurate). And for essentially no runtime cost, you're getting memory safety and exception safety. 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?