Skip to content

Instantly share code, notes, and snippets.

@ledbutter
Created August 13, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ledbutter/d51bdb8f1ef81fcc7e6c to your computer and use it in GitHub Desktop.
Save ledbutter/d51bdb8f1ef81fcc7e6c to your computer and use it in GitHub Desktop.
Compare String.Join and Aggregate()
IEnumerable<string> values = Enumerable.Repeat("Foo", 100);
Stopwatch watch = new Stopwatch();
watch.Start();
Console.WriteLine(String.Join("<br/>", values));
Console.WriteLine("Performance with Join: {0}", watch.Elapsed);
// "Performance with Join: 00:00:00.0001146"
watch.Restart();
Console.WriteLine(values.Aggregate ((x, y) => string.Format("{0}<br/>{1}", x, y)));
Console.WriteLine("Performance with Aggregate: {0}", watch.Elapsed);
// "Performance with Aggregate: 00:00:00.0002650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment