Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Terrible slowdown on .NET processing
Message
De
05/05/2006 11:41:45
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
05/05/2006 11:31:56
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01119485
Message ID:
01119629
Vues:
21
>>(Not sure if this can be an exact explanation).
>>Strings in .Net are reference types and immutable. That's when you concatanate a string with another new string is not simply added to the end of the other in memory, but a totally new string is created.
>>Within each call you're effectively creating a series of new strings in memory + a new lcHtml string.
>>.Net StringBuilder class is for things like this. Use it. It effectively optimizes the process and is fast. Yey another alternative is to create a stream and append to that stream. ie:
>>
>>Dim sb as new StringBuilder()
>>sb.Append(lcHTML)
>>                        If cCurrentField = "No_Claim" Then
>>for 1 to 8
>>  sb.AppendFormat(  "&ClaimNo={0}&MitTelAI={1}&Hd=1>", _
>>              Trim(oRow("No_Claim")), _
>>              LTrim(Str(oRow("AI")))   )
>>next
>>                        End If
>>
>>or: If you prefer:
>>sb.Append("&ClaimNo=")
>>sb.Append(Trim(oRow("No_Claim")))
>>sb.Append("&MitTelAI=")
>
>The StringBuilder() does not resolve the issue. If I have this, which means I am not executing anything, I obtain a processing time of one second:
>
>
>                        ' Process the hyperlinks, if any
>                        'lcHtml = lcHtml + Hyperlink()
>                        If cCurrentField = "No_Claim" Then
>                            Dim sb As StringBuilder = New StringBuilder()
>                            If False Then
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                sb.Append(oRow("No_Claim").ToString.Trim)
>                                lcHtml = lcHtml + sb.ToString
>                            End If
>                        End If
>
>
>If I remove the If False condition, I obtain a processing time of 7 seconds.

7 is long! But I still see a lcHTML = lcHTML + sb.ToString there. Initialize with new StringBuilder(lcHTML) instead. You might gain performance adding capacity parameter.
My alternative is using streams. Streams simply add to end.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform