Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Speed Up Your VB.NET Code
Optimization rules have changed under VB.NET. Here are eight new ways to build wicked-fast code.
by Francesco Balena

August 2002 Issue

Technology Toolbox: VB.NET

ADVERTISEMENT

VB.NET changes the way you write Visual Basic code. You learn quickly that most of the optimization tricks you've learned for VB6 won't work under VB.NET. For example, .NET memory allocation forces you to rethink how you process strings and other data types. In other cases, the problem isn't in the language. For instance, ADO.NET requires optimization techniques completely different from those for ADO.

I'll show you the eight more useful tips for making your VB.NET programs run like the wind. You can apply most of these techniques to C# as well because .NET languages are actually just a thin layer over the .NET Framework. Note that I took all timings by compiling the code without debug support and after ticking the Enable Optimizations option in the Configuration Properties | Optimizations page of the Project Properties dialog box.

1 Concatenate Strings With StringBuilder
Your first optimization trick involves sidestepping string concatenation. Consider this slow code:

' Create a comma-delimited list of all
' numbers in the range [1-10000]
Dim i As Integer, s As String
For i = 1 To 10000
   s &= CStr(i) & ", "
Next



Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home