VisualBasic.NET speed string operations with StringBuilder
Posted: Tue May 17, 2005 11:13 am
BB
Regular
Joined: Jun 23, 2004
Posts: 340
I had a Visual Basic.NET ASP.NET application that was digesting a text input file 3 megabytes in size with 30,000 lines. It was taking 20 minutes to complete! I began looking at different factors. The actual upload went like this:
and it used a System.Web.UI.HtmlControls.HtmlInputFile control on the web page. It completed within one second. So I knew that was not the problem.
It seemed that the Regex and Try/Catch statements were also not the problem. The real speed up came when I took out a String append step. I had a string called "Textboxstring" to which I kept appending message data. It would eventually reach about 40,000 lines. At the end, I would send this text data to the results web page.
My savior was the Stringbuilder class! My original code was like this:
Code:
Dim TextBoxString As String
within the loop I had
Code:
TextBoxString=TextBoxString & sampleText
I replaced it with:
Code:
Dim TextBoxString As New System.Text.StringBuilder
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest (c) 2006 by Group29 Productions.
You can syndicate Group29 Productions news with an RSS Feeder using the file backend.php