Monday, September 20, 2010

C# Performance

When C comes out, there must be some chaos about its performance is not as good as assembly language. I will start some posts to discuss the performance of C#, trying to help improve the performance of .NET language.

  1. var str = "";
  2. var str0 = String.Empty;
we can easily find out that str = str0; but which way is faster? 

the following is the disassembly from the first statement:
    Stloc_0 local_0

the following is the one from the second statement:
    Ldsfld System.String.Empty
    Stloc_1 local_1

It does not tell much, but when we actually run it using StopWatch, we can find the String.Empty is 5-6 times faster than empty string. I would not say the different is so huge because maybe it is my computer's configuration, but definitely the second statement is faster.

No comments: