Created
June 16, 2013 13:06
-
-
Save joeriks/5791981 to your computer and use it in GitHub Desktop.
This file contains 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
var sw = new System.Diagnostics.Stopwatch(); | |
var x = new []{"foo","bar","baz"}; | |
sw.Start(); | |
foreach(var iterations in Enumerable.Range(1,10000000)) | |
{ | |
var result = x.Aggregate ((a,s)=>a+ ", " + s); | |
} | |
sw.ElapsedMilliseconds.Dump(); |
This file contains 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
var sw = new System.Diagnostics.Stopwatch(); | |
var x = new []{"foo","bar","baz"}; | |
sw.Start(); | |
foreach(var iterations in Enumerable.Range(1,10000000)) | |
{ | |
var result = string.Join(", ",x); | |
} | |
sw.ElapsedMilliseconds.Dump(); |
It's one of these situations where readability should be preferred over the unnoticeable performance difference ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result : Aggregate 4.3 secs, string.join 2.3 secs. For 10.000.000 iterations. No meaningful difference imo. Definately not a reason to go string.join if you are already doing linq to process your data.