Skip to content

Instantly share code, notes, and snippets.

@cryks
Created October 18, 2010 16:18
Show Gist options
  • Save cryks/632509 to your computer and use it in GitHub Desktop.
Save cryks/632509 to your computer and use it in GitHub Desktop.
Stopwatch sw = new Stopwatch();
string str = new string(' ', 1024 * 1024 * 8);
sw.Restart();
{
var ret = str
.Select(c => string.Format("[{0}]", c))
;
string.Join("", ret);
}
Console.WriteLine("{0} milliseconds", sw.ElapsedMilliseconds);
// 2476 milliseconds
sw.Restart();
{
var ret = str
.Aggregate(new StringBuilder(), (sb, c) => sb.AppendFormat("[{0}]", c))
.ToString()
;
}
Console.WriteLine("{0} milliseconds", sw.ElapsedMilliseconds);
// 1343 milliseconds
Console.ReadKey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment