vbnet String versus StringBuilder
Using System.Text Sub Main() Dim sDate, eDate, sTime, sbTime As Long Dim LoopCount As Long = 10000 Dim s As String = "" Dim sb As New StringBuilder sDate = Now.Ticks For i = 0 To LoopCount s = s & Guid.NewGuid.ToString Next eDate = Now.Ticks sTime = (eDate - sDate) 'Console.WriteLine(s) Console.WriteLine("String Concatenation: " & sTime.ToString) sDate = Now.Ticks For i = 0 To LoopCount sb.Append(Guid.NewGuid.ToString) Next eDate = Now.Ticks sbTime = (eDate - sDate) 'Console.WriteLine(sb.ToString) Console.WriteLine("StringBuilder: " & sbTime.ToString) Stop End Sub
Highlights the performance advantage of using StringBuilder.
Updated: Saturday 9th October 2010, 10:54pm
There are 0 comments
Comments are currently closed.