Created
October 18, 2010 16:18
-
-
Save cryks/632509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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