Put some strings together

Started by
86 comments, last by peter86 21 years, 4 months ago
quote:Original post by AndyOxfeld
Are we talking about people who have never programmed before?

It appears that way.
Advertisement
quote:Original post by cpujeff122
I'm not sure, why would you?

I have no idea, but it was you was implying using C++ features is somehow a problem, so it is you who should answer the question.
quote:
The STDC works a lot faster if you just use the stack (like you can), but apparently I'm not allowed to do that for this test.

You know, your efficiency proofs are all very exciting an' all, but you're going to a lot of effort to prove nothing. You can't prove that c-strings will be faster for my application, because you don't know what it is, just like you can't prove they will be faster for the OP, or you can't prove they are faster for *any* application without actually measuring it. So, the question is, why are you engaging in wholesale premature optimisation? You're going to a lot of effort to make yourself look a rank amateur.

[edited by - SabreMan on December 6, 2002 2:34:45 PM]
quote:
You know, your efficiency proofs are all very exciting an'' all, but you''re going to a lot of effort to prove nothing. You can''t prove that c-strings will be faster for my application, because you don''t know what it is, just like you can''t prove they will be faster for the OP, or you can''t prove they are faster for *any* application without actually measuring it. So, the question is, why are you engaging in wholesale premature optimisation? You''re going to a lot of effort to make yourself look a rank amateur.


You still haven''t proven that STL is faster or easier for the OP''s application. At least I backed my arguments up with code and data; you back yours up with theoretical ramblings and "what ifs".

- Andy Oxfeld
quote:Original post by cpujeff122
You must have a slow computer. Running my code on a pentium 133 yields

STDC time: 2.200000 seconds
STL time: 4.13 seconds

And that's with -O2 and making the stdc one allocate memory.


I ran your code on my comp, MSVC7, dual athlon 1.2 ghz:
With 10M iterations(1M is too small):

STDC time: 3.828 seconds
STL time: 1.765 seconds

Also, I had to include malloc.h for the STDC version.

Then, I ran it on cygwin(gcc 2.95) for fun:

STDC time: 3.50 seconds
STL time: 2.547 seconds



[edited by - sjelkjd on December 6, 2002 3:11:50 PM]
quote:Original post by AndyOxfeld
You still haven''t proven that STL is faster[...]

I haven''t made any outlandish claims that it is, so why would I try and prove that it is? I''ve simply said that you don''t know if it''s faster or not.
quote:
[...]or easier[...]

For the third time, I provided this example of "putting strings together":

    #include <string>int main(){using std::string;  string s1 = "Things ";  string s2 = "and stuff";  // put two strings together:  string s3 = s1 + s2;}    

I still claim the single operator+ call is obviously the easiest way of doing it.
quote:
At least I backed my arguments up with code and data; you back yours up with theoretical ramblings and "what ifs".

I asked you to back up what you''ve said. You made three claims: "faster", "easier", "more portable". You''ve not proven any of them. I haven''t had very much to back up because I haven''t made a load of wild claims. I''ve simply asked you to prove your claims or back down, and you''ve continued to make whiny noises.
quote:Original post by AndyOxfeld
You still haven't proven that STL is faster or easier for the OP's application. At least I backed my arguments up with code and data; you back yours up with theoretical ramblings and "what ifs".

- Andy Oxfeld


If you are deluded enough to think that C-style strings are "easier" than std::string, that's fine, but don't peddle that bullshit around here. All you're doing is confusing people who don't know any better.

There are exactly two reasons why I would use a c-style string in c++.

1) To learn how memory management works.
2) If I had a performance problem in my app, and strings were the cause, and I tried everything else on an algorithmic and coding level to alleviate the performance problem.

You are like that idiot that came in here claiming that ASM was just as good as c++, and could write ASM just as quickly as he could write c++. If that's the case, good for you. However, I seriously doubt it is true, and moreover it is not true for the population in general.

How many times have you seen some c++ newbie trying to copy a "string" by doing this:

char* a = "my first string";
char* b = a;
//modify b

C-style strings are a horrible way to learn string handling, especially considering that a higher level alternative exists(std::string).

I also think that the benchmarks done support the argument that, in an apples-to-apples comparison, std::string is faster than string.h functions.

[edit]Not that I am saying std::string is faster than string.h stuff, just that in this particular benchmark it appears to be.



[edited by - sjelkjd on December 6, 2002 3:21:11 PM]
quote:
I thought your main argument for why to use C++ std::string is ease of use. Is that line you just pasted more or less complicated than char str[40]; ?


Indeed it is ease of use, I fail to see the connection between me disproving the people that said it was not possible to use stack memory in an allocator and that std::string is hard to use.

That line is substantially more complicated that char str[40], but you don''t need to use it. It was a demonstration that it is equally possible to allocate c++ strings on the stack - not that it''s a good idea, or even worth the time it takes to implement.

quote:
Are we talking about people who have never programmed before?


Sigh. It was meant to illustrate a point. Which is easier to understand upon first glance? This is a good indication of how easy/hard it will be to maintain at a later date. What happens if I decide to change the length of my string? I have to change char ary[50]. Then I have to go through and change all occurrences of 50 that relate to that string in my code. What happens when I want to change the length of a c++ string? Nothing, I use it and it grows automatically. User friendly. C style strings are anything but.

Indeed we can get around this limitation by encapsulating the buffer and size in a class, then we could do strncpy(str.getBuffer(),"Hello ",str.getSize()), but this is hardly good oop design. Furthermore, we already have a clean and pretty efficient implemenation done for us and it''s also standard!

I think I have just demonstrated an area where C++ strings are more user friendly than C style strings and indeed, more consistent with OOP programming.
S:N too low. Excess FUD.

This topic is closed to new replies.

Advertisement