This started out innocently enough - I was looking for a simple way to start experimenting with the Performance Wizard tool that's included with Visual Studio Team Edition for Developers so to keep things simple, my Performance Wizard "hello world!" became this little bit of code:
Imports System.text
Module PerfJunkie
Private ReallyBigString As String
Sub Concatenate(ByVal Junk As String)
ReallyBigString = ReallyBigString & Junk
End Sub
Sub Main()
For i As Int16 = 0 To (Int16.MaxValue - 1)
Concatenate(CStr(i))
Next
Console.WriteLine(ReallyBigString)
Console.ReadLine()
End Sub
End Module
Well of course we can immediately see some areas where this little diddy can be optimized to perform better. For one, the use of a Stringbuilder versus String... in this case using String with concatenation accounts for nearly 80% of the processing time alone. But after that rather obvious improvement, I started to explore...and in the end I got the whole thing to dump out the results almost immediately after hitting F5 to run...a nice improvement over the original run time of over 11 seconds (granted I've working on a rather underpowered machine here, but them's the breaks I live with!)
So then - what other improvements can you see with this? I've already come to my own conclusion while working through and becoming familiar with the Performance Wizard tool (really a neat tool if you ask me!) but I'm curious to see what other minds are thinking.