473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?

Aug 11 '07 #1
16 3657
On 2007-08-11 16:10, yu****@sina.com 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 shit 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
Aug 11 '07 #2
On Aug 11, 10:19 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-08-11 16:10, yu_...@sina.com 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 shit 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

Aug 12 '07 #3
On 2007-08-12 11:35, yu****@sina.com wrote:
On Aug 11, 10:19 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
>On 2007-08-11 16:10, yu_...@sina.com 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 shit 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
Aug 12 '07 #4
<yu****@sina.co mwrote in message
news:11******** **************@ g12g2000prg.goo glegroups.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.
Aug 13 '07 #5
"Jim Langston" <ta*******@rock etmail.comwrote in message
news:H_******** *****@newsfe04. lga...
<yu****@sina.co mwrote in message
news:11******** **************@ g12g2000prg.goo glegroups.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.
Aug 13 '07 #6
Jim Langston wrote:
"Jim Langston" <ta*******@rock etmail.comwrote in message
news:H_******** *****@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?
Aug 13 '07 #7
"Victor Bazarov" <v.********@com Acast.netwrote in message
news:8J******** *************** *******@comcast .com...
Jim Langston wrote:
>"Jim Langston" <ta*******@rock etmail.comwrote in message
news:H_******* ******@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.
Aug 13 '07 #8
On Aug 13, 5:03 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
"Victor Bazarov" <v.Abaza...@com Acast.netwrote in message
news:8J******** *************** *******@comcast .com...
Jim Langston wrote:
"Jim Langston" <tazmas...@rock etmail.comwrote in message
news:H_******* ******@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++.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 13 '07 #9
On Aug 12, 6:58 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-08-12 11:35, yu_...@sina.com wrote:


On Aug 11, 10:19 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-08-11 16:10, yu_...@sina.com 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 shit 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- Hide quoted text -

- Show quoted text -
Actually we are dealing with telecomunicatio n protocols, like SIP and
Diameter. Most contents are now text based, so we are right dealing
with large amount of strings, and sometimes the string can be large
(To about Mega bytes). Most operation on string would be copy, find
and concatecation, very little modify or replace operation.

And std::string haven't been widely used yet, so I can't just change
it overnight. That's why I have to do some work outside our
application, and the analysis should better cover as much operations
on strings of different length. That's not a very simple work to do,
I'm just lazy and wonder if somebody had done that.

Regards,
Kevin

Aug 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
11018
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include <string> #include <vector> #include <cstring> // presume s from somewhere, such as:
3
3821
by: Mathieu Malaterre | last post by:
Hello, I guess this might be a very dummy question, but I couldn't find an answer in the group's archive. I am reading DICOM files, and to store the string read I use std::string. Unfortunately there is case where the string can be '\0\0' Is this a defined bahavior when you do this kind of operation : const char *s = "\0\0";
8
5146
by: puzzlecracker | last post by:
Does string class take into consideration a poterntial buffer overflow issue? or does std:string::c_str() member functions does? what are the preventives?
24
17463
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET managed C++. It seems to work fine, but everyone knows that programs with errors can still appear to "work fine" :) I am working with VS .NET 2003; I am unable to upgrade to 2005 at this time, so I cannot use the newer syntax or features. ...
9
3770
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in code. for example, this is bad practice: header.h #include <string> using std::string;
2
10890
by: pookiebearbottom | last post by:
Just looking for opinion on which of the 3 methods below people use in their code when they convert a 'const char *' to a 'const std::string &' came across #3 in someone's code and I had to think for a sec. At first I read it as converting a 'const char *' to a 'std::string *' void f(const std::string &s) { std::cout << s.size() << "\n";
6
4851
by: SteelSide | last post by:
Ive searched and searched,but havent been able to get it to work. ----------------- #include <iostream> using namespace std; std::string tempHostNameStr = "s1e2.hidden.thingy.org"; char szHostName;
29
23170
by: aarthi28 | last post by:
Hi, I have written this code, and at the end, I am trying to write a vector of strings into a text file. However, my program is nor compiling, and it gives me the following error when I try to write to the file: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) I don't know what I am doing wrong. I have posted my entire program
12
12411
by: sas | last post by:
hi, i need that because the path functions for windows, like PathAppend and PathRemoveFileExt accept a writable zero terminated char*, but i didn't find that for std::string, with CString, i usually use GetBuffer for that LPTSTR CString::GetBuffer( int nMinBufLength )
0
8067
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.