Re: Is there systematic performance comparison of std::string and c style string?
"James Kanze" <james.kanze@gmail.com> wrote in message
news:1186993213.472666.190640@k79g2000hse.googlegroups.com...
On Aug 13, 5:03 am, "Jim Langston" <tazmas...@rocketmail.com> wrote:
"Victor Bazarov" <v.Abaza...@comAcast.net> wrote in message
news:8JydnTuOLfB1WyLbnZ2dnUVZ_uejnZ2d@comcast.com...
Jim Langston wrote:
"Jim Langston" <tazmas...@rocketmail.com> wrote in message
news:H_Ovi.34$665.17@newsfe04.lga...
In my own testing the overhead of std::string .vs. c-style strings
was measured in microseconds. I.E. very negligable.
Wait,not micro, the one that is smaller than nano. Lets see, mili,
micro, nano, ... umm.. dang.
Pico? Atto? Femto?
Pico, that's it. It took about 4 pico seconds longer to
allocate a std::string than to use a c-style array in my
testing. Negligable for any application.
Picosecond differences are probably less than the resolution of
your measurement system; it would be more accurate to say that
you found no measurable difference. But that still doesn't tell
us anything, because we don't know what you were measuring.
Note too that for any given activity, the implementation of
std::string can make a significant difference. For some things,
the implementation in g++ is significantly faster than that in
VC++, for others, the reverse is true. (G++ uses reference
counting; VC++ deep copy with the small string optimization. If
you don't copy much, and most of your strings are short, VC++
will be faster; if you copy long strings a lot, g++.)
=========
Yes, I had to measure doing it a few million times to tell the difference
between a c-style string and std::string. And results can be thrown off
depending on how the compiler decides to optimize the code. But I was able
to get a difference of around 4 pico seconds using std::string than a
c-style string when I averaged the results. And I found it negligable.
I did this to show someone who was insistant on using c-style strings than
std::strings because he thought std::strings were slower. Showing him the
code and results he agreed that std::strings were usable.