Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is there systematic performance comparison of std::string and c style string?

Reply
Thread Tools

Is there systematic performance comparison of std::string and c style string?

 
 
yu_kuo@sina.com
Guest
Posts: n/a
 
      08-11-2007
Is there any comparison data on perfomance difference between
std::string and c style string? Or maybe if there are source code
which could be used to measuer on different compiler/platform, in a
systematic way?

 
Reply With Quote
 
 
 
 
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a
 
      08-11-2007
On 2007-08-11 16:10, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Is there any comparison data on perfomance difference between
> std::string and c style string? Or maybe if there are source code
> which could be used to measuer on different compiler/platform, in a
> systematic way?


Most certainly there is, google is your friend. I believe if you include
the word rope in the search you'll find some. Remember though that all
the benchmarks in the world does not mean **** if they don't measure
what you need, so instead of looking for other peoples benchmarks
perform your own with the code you need to run.

--
Erik Wikström
 
Reply With Quote
 
 
 
 
yu_kuo@sina.com
Guest
Posts: n/a
 
      08-12-2007
On Aug 11, 10:19 pm, Erik Wikström <(E-Mail Removed)> wrote:
> On 2007-08-11 16:10, (E-Mail Removed) wrote:
>
> > Is there any comparison data on perfomance difference between
> > std::string and c style string? Or maybe if there are source code
> > which could be used to measuer on different compiler/platform, in a
> > systematic way?

>
> Most certainly there is, google is your friend. I believe if you include
> the word rope in the search you'll find some. Remember though that all
> the benchmarks in the world does not mean **** if they don't measure
> what you need, so instead of looking for other peoples benchmarks
> perform your own with the code you need to run.
>
> --
> Erik Wikström


Thanks for your reply and suggestion. Actually I myself am prety
convinced to prefer std::string, but it's simply not a common sense of
my colleagues. That's why I'm searching for hard proofs to convince
people. I did googled for some time, but didn't find what I can
directly use. Any way I could write some code to compare functionality
we are interested, just as you have suggested.

Regards,
Kevin

 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      08-12-2007
On 2007-08-12 11:35, (E-Mail Removed) wrote:
> On Aug 11, 10:19 pm, Erik Wikström <(E-Mail Removed)> wrote:
>> On 2007-08-11 16:10, (E-Mail Removed) wrote:
>>
>> > Is there any comparison data on perfomance difference between
>> > std::string and c style string? Or maybe if there are source code
>> > which could be used to measuer on different compiler/platform, in a
>> > systematic way?

>>
>> Most certainly there is, google is your friend. I believe if you include
>> the word rope in the search you'll find some. Remember though that all
>> the benchmarks in the world does not mean **** if they don't measure
>> what you need, so instead of looking for other peoples benchmarks
>> perform your own with the code you need to run.
>>
>> --
>> Erik Wikström

>
> Thanks for your reply and suggestion. Actually I myself am prety
> convinced to prefer std::string, but it's simply not a common sense of
> my colleagues. That's why I'm searching for hard proofs to convince
> people. I did googled for some time, but didn't find what I can
> directly use. Any way I could write some code to compare functionality
> we are interested, just as you have suggested.


I might have miss understood you original question a bit, I thought that
you wanted to know which was the best performer for a certain kind of
use (such as really large amounts of strings or really large strings) in
which case there might sometimes be some benefits to using C-strings.

But if you mean usage of std::string vs. C-strings in general then I'm
very hard pressed to come up with any argument in favour of C-strings
but it's quite easy to find arguments for std::string (ease of use, no
risk of overflows, don't have to allocate memory manually etc.). In fact
one very good argument against using C-strings is that most buffer
overflow attacks are caused by improper usage of C-strings, and if
std::string had been used instead the code would have been much simpler
and more safe. As for speed, I'd say that std::string is fast enough for
most usages and if your application is an exception you'd probably know
it due to profiling and benchmarks you've already done.

--
Erik Wikström
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      08-13-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Is there any comparison data on perfomance difference between
> std::string and c style string? Or maybe if there are source code
> which could be used to measuer on different compiler/platform, in a
> systematic way?


In my own testing the overhead of std::string .vs. c-style strings was
measured in microseconds. I.E. very negligable.


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      08-13-2007
"Jim Langston" <(E-Mail Removed)> wrote in message
news:H_Ovi.34$(E-Mail Removed)...
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> Is there any comparison data on perfomance difference between
>> std::string and c style string? Or maybe if there are source code
>> which could be used to measuer on different compiler/platform, in a
>> systematic way?

>
> 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.


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-13-2007
Jim Langston wrote:
> "Jim Langston" <(E-Mail Removed)> wrote in message
> news:H_Ovi.34$(E-Mail Removed)...
>> 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?


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      08-13-2007
"Victor Bazarov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> Jim Langston wrote:
>> "Jim Langston" <(E-Mail Removed)> wrote in message
>> news:H_Ovi.34$(E-Mail Removed)...
>>> 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.


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      08-13-2007
On Aug 13, 4:02 am, "Jim Langston" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message


> news:(E-Mail Removed) oups.com...


> > Is there any comparison data on perfomance difference between
> > std::string and c style string? Or maybe if there are source code
> > which could be used to measuer on different compiler/platform, in a
> > systematic way?


> In my own testing the overhead of std::string .vs. c-style strings was
> measured in microseconds. I.E. very negligable.


My own testing found several orders of magnitude. Developing
something using C style strings might take a week, where with
std::string, it would be a couple of hours.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      08-13-2007
On Aug 13, 5:03 am, "Jim Langston" <(E-Mail Removed)> wrote:
> "Victor Bazarov" <(E-Mail Removed)> wrote in message


> news:(E-Mail Removed). ..


> > Jim Langston wrote:
> >> "Jim Langston" <(E-Mail Removed)> wrote in message
> >>news:H_Ovi.34$(E-Mail Removed)...
> >>> 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++.)

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of 2 files and generating the output based on comparison Deepu Perl Misc 1 02-07-2011 03:09 PM
Is there any way to keep a systematic documentation of credi ANDANI The Lounge 2 06-04-2009 01:07 AM
systematic miscompilation of volatile accesses John Regehr C Programming 0 04-29-2008 03:30 AM
systematic file(s) deletion NickName Java 39 01-15-2007 02:17 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM



Advertisments