C# Performance

If you're concerned about performance, you should read Rico
Mariani's blog

Rico is an architect on the CLR team, and, coincidentally, is one of the developers
who interviewed me way back in 1994.


Comments (2)

  1. Blair Stephenson says:

    Speaking of peformance. I’ve converted a VB6 program to C#. It takes all the transactions overnight and parses the file (500mb) and produces a new file for BCP to SQL.

    The VB6 program would take around 90 minutes and use 100% CPU.

    The C# program takes around 90 seconds. I’m not really doing anything special (apart from using StringBuilder on each row) and it uses around 50% CPU.
    There’s around a million rows.

    I think the major difference is the way VB6 converted all strings to Unicode.

    Anyway, it’s one of the major real world improvements .Net brings to us.

    Good work MS.

  2. Zac Spery says:

    C# actually builds large strings much slower than VB, unless you’re using StringBuilder. But it’s pretty much negligible if you use an old trick…that is, don’t let your VB string get over 64k, append it to another string, blank out the original, and continue building on the small string.

    For example:

    For i = 1 To 120000

    strTemp = strTemp + " "

    Next i

    Runs in 25 secs on my computer. This:

    For i = 1 To 40

    For i2 = 1 To 3000

    strAppend = strAppend + " "

    Next i2

    strTemp = strTemp + strAppend

    strAppend = ""

    Next i

    Run in .11 secs. The C# equivalents:

    for (i=0; i<120000;i++)


    strTemp += " ";


    Runs in 52 secs. But the StringBuilder equivalent beats them all:

    StringBuilder strTemp = new StringBuilder();

    for (i=0; i<120000;i++)


    strTemp.Append (" ");


    Run in .02 secs

Skip to main content