Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    Very interesting. I got an average of 224ms vs. 48ms, an x4.66 improvement, even better than your x3.72. I wonder if there is a post-compilation tool that can rewrite the IL of string.Format that doesn't use any composite formatting features (i.e. just simple {0}) and replace them with the considerably faster string concatenation. I wonder such a feat is achievable with an existing IL rewriter such as PostSharp. Commented Sep 29, 2011 at 15:24
  • 33
    Strings are immutable, this means the same tiny piece of memory is used over and over in your code. Adding the same two strings together and creating the same new string over and over again doesn't impact memory. .Net is smart enough just to use the same memory reference. Therefore your code doesn't truly test the difference between the two concat methods. See code in my answer below. Commented Nov 13, 2012 at 1:21
  • 1
    Honestly, I always concatenate since it's easier to read for me and wow it's faster :) Commented Jan 20, 2014 at 2:09
  • So speed is the only reason to choose one over the other? Commented Oct 26, 2016 at 22:58