Home All Groups Group Topic Archive Search About

String vs. Stringbuilder speed parsing questio

Author
7 Feb 2006 12:39 PM
almurph@altavista.com
Hi everyone,


    Can you help me please? Say you have hashtable of about 500 key/value
pairs. This hashtable has to parse a word. If the word matches the key
the then said word must be replaced by the value.
    My question is though - would parsing occur faster if the word is
input as a type string or a type stringbuilder? Do you see my point?
    Would appreciate any comments/experiences/suggestions that anyone has
on this one...

Al.

Author
7 Feb 2006 12:49 PM
Patrice
Your best bet is to test. StringBuilder are faster if you have significants
processing to do on a string and/or if those strings are big.

Here I don't really see what you mean (do you mean you would use
stringbuilders as keys instead of strings hoping it would speed up data
retrieval, if yes IMO you won't see any difference). For a start you can try
to time your code to see what is the slowest part...

--
Patrice

<almu***@altavista.com> a écrit dans le message de
Show quoteHide quote
news:1139315964.067015.254030@g44g2000cwa.googlegroups.com...
> Hi everyone,
>
>
> Can you help me please? Say you have hashtable of about 500 key/value
> pairs. This hashtable has to parse a word. If the word matches the key
> the then said word must be replaced by the value.
> My question is though - would parsing occur faster if the word is
> input as a type string or a type stringbuilder? Do you see my point?
> Would appreciate any comments/experiences/suggestions that anyone has
> on this one...
>
> Al.
>
Author
7 Feb 2006 1:14 PM
Carlos J. Quintero [VB MVP]
Hi Al,

The hash table is fine with String. The StringBuilder is mostly used to
build strings concatenating small strings many times or replacing/inserting
text inside a large string, so you have to see if this fits in your problem,
which surely does for replacing the words by the new ones in the paragraph
that you want to process.


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


<almu***@altavista.com> escribió en el mensaje
Show quoteHide quote
news:1139315964.067015.254030@g44g2000cwa.googlegroups.com...
> Hi everyone,
>
>
> Can you help me please? Say you have hashtable of about 500 key/value
> pairs. This hashtable has to parse a word. If the word matches the key
> the then said word must be replaced by the value.
> My question is though - would parsing occur faster if the word is
> input as a type string or a type stringbuilder? Do you see my point?
> Would appreciate any comments/experiences/suggestions that anyone has
> on this one...
>
> Al.
>
Author
7 Feb 2006 2:12 PM
Cor Ligthert [MVP]
Al,

A string is an immutable string of characters
A stringbuilder is a muttable string of characters. Therefore it needs at
least instructions to set it to an immutable string of charaters that you
probably need. (ToString)

Cor
Author
7 Feb 2006 2:55 PM
almurph@altavista.com
Patrice, Carlos & Cor - thank you all for your comments.

Cheers,
Al.