Skip to content

Instantly share code, notes, and snippets.

@joeriks
Created June 16, 2013 13:06
Show Gist options
  • Save joeriks/5791981 to your computer and use it in GitHub Desktop.
Save joeriks/5791981 to your computer and use it in GitHub Desktop.
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();
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();
@joeriks
Copy link
Author

joeriks commented Jun 16, 2013

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.

@bomortensen
Copy link

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