Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Terrible slowdown on .NET processing
Message
From
05/05/2006 06:17:01
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
05/05/2006 02:25:01
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01119485
Message ID:
01119517
Views:
29
This message has been marked as the solution to the initial question of the thread.
>I just found something that I just can't find the reason. I have a terrible slowdown in one of my .NET application.
>
>If I have this:
>
>
>                        If cCurrentField = "No_Claim" Then
>                            lcHtml = lcHtml + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>"
>                        End If
>
>
>as part of a loop which is executed 200 times, it will take one second to execute the loop 200 times.
>
>But, if I have this:
>
>
>                        If cCurrentField = "No_Claim" Then
>                            lcHtml = lcHtml + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>" + "&ClaimNo=" + Trim(oRow("No_Claim")) + "&MitTelAI=" + _
>                             LTrim(Str(oRow("AI"))) + "&Hd=1>"
>                        End If
>
>
>as part of a loop which is executed 200 times, it will take 7 seconds to execute the loop 200 times.
>
>What is going on? Why is it that simply adding a longer string causes the process to crawl?

Michel,
(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=")
...
series.

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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform