 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
persenaama Guest
|
Posted: Fri Jan 27, 2006 11:05 am Post subject: Re: std::string performance (Sun implementation) |
|
|
This code, and the one that Markus posted earlier don't really show
either std::strlen or std::string::length to be any faster than the
other, just ways to use either poorly, and that description only holds
when it makes any real world difference.
You can write less than good code with either, it is also possible to
write good code with either. All it takes is experience and a brain to
capitalize on it... agreed?
The biggest advantage of std::string is the management of the object's
member data, it makes higher level code easier to write and read,
basicly less maintenance required so I tend to personally go with that
approach. Most of the code I write isn't performance critical, actually
very little is. On the other hand, most applications or parts of
application I write, could easily be bottlenecks (I write graphics
drivers for embedded graphics processors) but then again, in that field
code is never fast enough, so better do architechtural decisions that
are wise and leave implementation less headroom to cause problems. But
that's not very interesting to the rest of the world. :)
|
|
| Back to top |
|
 |
persenaama Guest
|
Posted: Fri Jan 27, 2006 11:12 am Post subject: Re: std::string performance (Sun implementation) |
|
|
Am I the only one to miss the point of these performance comparisons
you posted, but why compile the code to be as slow as possible when
trying to decide which is faster? I don't get it?
|
|
| Back to top |
|
 |
Ben Pope Guest
|
Posted: Fri Jan 27, 2006 11:47 am Post subject: Re: std::string performance (Sun implementation) |
|
|
persenaama wrote:
| Quote: | Am I the only one to miss the point of these performance comparisons
you posted, but why compile the code to be as slow as possible when
trying to decide which is faster? I don't get it?
|
I believe I made the same comment, no optimisations in the code. I
don't understand.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
|
|
| Back to top |
|
 |
mlimber Guest
|
Posted: Fri Jan 27, 2006 1:37 pm Post subject: Re: std::string performance (Sun implementation) |
|
|
jortizclaver wrote:
| Quote: | I tried yesterday using Sun Workshop 10 and linking with the STLPort
libraries it includes and I have to say execution times has plummeted
about 30% and now difference between char* implementation and
std::string is not that big. Using a very very basic test program, it's
a 1:1.5 ratio (no doubt in other tasks std::strings will beat char*)
Those results are perfectly valid for me. I think I'll use strings.
Thanks,
Jorge
|
Glad we could help. :-)
Cheers! --M
|
|
| Back to top |
|
 |
Daniel T. Guest
|
Posted: Fri Jan 27, 2006 1:40 pm Post subject: Re: std::string performance (Sun implementation) |
|
|
In article <1138281572.454328.96060 (AT) g14g2000cwa (DOT) googlegroups.com>,
"jortizclaver" <jortizclaver (AT) gmail (DOT) com> wrote:
| Quote: | Hi,
I'm about to develop a new framework for my corporative applications
and my first decision point is what kind of strings to use: std::string
or classical C char*.
Performance in my system is quite importante - it's not a realtime
system, but almost - and I concern about std::string performance in
terms of speed. No doubt to use std implementation is a lot easier but
I can't sacrifice speed.
I'm using Sun Workshop 6. A very basic test shows processing with
std::string can be 3 times slower than using char*. Is there any
improvement in later versions?
|
The C++ standard does not specify the complexity of basic_string
operations, as such there is no guarantee that std::string will be as
fast as using a C char*.
Of course, this also means you can implement your own string classes and
have them conform to the standard rather easily. Back when I first
started using string classes, the popular thing to do was to use
reference counting internally, lately most strings are implemented
basically like a vector<char>, one could however implement it in terms
of a deque<char>.
What is it you do with your strings in your program? In most programs,
different string like objects are used in different ways; some must be
able to resize, some are always a fixed size but must be able to mutate
their contents, and some always have a fixed size and fixed contents.
Some must be able to efficiently handle insertions in the middle (more
efficiently than vector<char>.
A reasonably large company with very tight performance requirements
would be best served by having several different string implementations,
using std::string for everything would probably not be the best choice;
nor would just using C char* for everything.
|
|
| Back to top |
|
 |
persenaama Guest
|
Posted: Fri Jan 27, 2006 3:16 pm Post subject: Re: std::string performance (Sun implementation) |
|
|
It would interesting to see some statistics, but unlike they exist
because most have better things to do. But here's what I observed about
string class uses (from personal experience, don't try to inflict
opinion to anyone)
Most typical use I observe is to use string object to store names of
objects and similiar use: basicly, just storing text. <- doh? ;-)
Another use is stringstream / sprintf -like usage, where strings are
created from, typically from (again, just observation) binary data.
Common practise when writing to file and the format is ascii as an
example.
I can think of countless other uses aswell but those two in my
experience are present practically everywhere.
For use #1 the performance is rarely critical when constructing the
string object. When using the name for indexing somekind of fast
comparison might be useful (insertion to a map might be one place where
this is useful optimization to have?)
I could go on, but I recognize the futility of iterating my own
personal experience in lack of statistics with very large number of
samples. )
I don't remember string performance ever being a real problem in any
application I've written. I suppose I haven't written enough
applications to worry about this. I can think of instances where it may
pose a problem, but I haven't actually written such software (yet) so I
rather not comment on that -- however -- comments by those who have are
welcome!
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Fri Jan 27, 2006 4:17 pm Post subject: Re: std::string performance (Sun implementation) |
|
|
jortizclaver wrote:
| Quote: | Hi,
I'm about to develop a new framework for my corporative applications
and my first decision point is what kind of strings to use: std::string
or classical C char*.
Performance in my system is quite importante - it's not a realtime
system, but almost - and I concern about std::string performance in
terms of speed. No doubt to use std implementation is a lot easier but
I can't sacrifice speed.
I'm using Sun Workshop 6. A very basic test shows processing with
std::string can be 3 times slower than using char*. Is there any
improvement in later versions?
|
You should use generic methods of accessing an object that acts like a
std::string, then you can reimplement as you need. I myself found that
profiling rarely focuses on string operations, if ever.
I did do some performance tests of std::string vs. char[]. Using
std::string poorly, such as creating unnecissary temporaries (don't use
operator +), can greately reduce execution speed if in fact you are in
an area of code that needs speed. stringstream was much faster than
sprintf but strcat was also quite a bit faster than append().
Really its a balancing act. There are many costs of using char[] that
have nothing to do with execution speed including debug time caused by
buffer overruns (code riddled with static sized char arrays can really
cost when it comes time to change features). In the end the cost of
using std::string is negligable (when used reasonably) in execution
speed but of major benefit in development time when compared to char[].
If std::string is costing too much you probably need to look closer at
your algorithm, not the string implementation.
And remember, profile before optimizing. I get into arguments with
coworkers about std::string vs. char[] all the time (their claim is the
cost of allocation which I found to be negligable - big believers in
the Clib part of C++) and std::string is never in the top of a
profile...it is always something else. On the other hand it took me 12
hours to track down a buffer overflow in a char[]...
|
|
| Back to top |
|
 |
Alex Vinokur Guest
|
Posted: Fri Jan 27, 2006 4:18 pm Post subject: Re: std::string performance (Sun implementation) |
|
|
"Ben Pope" <benpope81_REMOVE_ (AT) gmail (DOT) com> wrote
| Quote: | persenaama wrote:
Am I the only one to miss the point of these performance comparisons
you posted, but why compile the code to be as slow as possible when
trying to decide which is faster? I don't get it?
I believe I made the same comment, no optimisations in the code. I
don't understand.
[snip] |
The performance comparisons I posted is an example of using C++ Program Perfometer. The user can use the Perfometer to get
comparison of various algorithms for various levels of optimization.
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|