Stringbuilder in C#

  • Thread starter Thread starter lovey dovey via .NET 247
  • Start date Start date
L

lovey dovey via .NET 247

(Type your message here)

--------------------------------
From: lovey dovey


I need help for the following exercise.I am new to c#.Pls help me.
Can anyone explain the difference between String & StringBuilder class.I need to do a
performance comparison between both classes(come up with an algorithm!
What is needed to do a performance comparison between creating or
concatenating string and concating data inside StringBuilder) and i need to plot
the results in excel spreadsheet.
 
school assignment!
Lovey Dovey, what have you done so far?

What I would do:
build a test driver that runs a loop 50000 times
in each loop, concatenate N strings of length L
do this 2 ways: with + and with StringBuilder
measure the start and finish time of each loop
Repeat test M times for precision.
spit out results in a CSV file, or better, export directly to Excel.
 
lovey dovey via .NET 247 said:
(Type your message here)

--------------------------------
From: lovey dovey


I need help for the following exercise.I am new to c#.Pls help me.
Can anyone explain the difference between String & StringBuilder class.I need to do a
performance comparison between both classes(come up with an algorithm!
What is needed to do a performance comparison between creating or
concatenating string and concating data inside StringBuilder) and i need to plot
the results in excel spreadsheet.

-----------------------
Here is the basic difference between String and StringBuilder, as quoted
from the help in Visual Studio .NET 2003:
<quote>
The String object is immutable. Every time you use one of the methods in the
System.String class, you create a new string object in memory, which
requires a new allocation of space for that new object. In situations where
you need to perform repeated modifications to a string, the overhead
associated with creating a new String object can be costly. The
System.Text.StringBuilder class can be used when you want to modify a string
without creating a new object. For example, using the StringBuilder class
can boost performance when concatenating many strings together in a loop.

<unquote>

StringBuilder objects are mutable. I.e. the existing contents can be
modified without allocation of space for a new object.

Follow Dino's suggestion to create a test which will produce enough
repetitions to show the difference.
 
I need help for the following exercise.I am new to c#.Pls help me.
Can anyone explain the difference between String & StringBuilder class.I need to do a
performance comparison between both classes(come up with an algorithm!
What is needed to do a performance comparison between creating or
concatenating string and concating data inside StringBuilder) and i need to plot
the results in excel spreadsheet.


Write the results into a csv (comma separated values) file so excel can open
it:

1234;23432;2343;2343
3756;453;4566;4566

and so on.
 
Back
Top