Skip to content

Instantly share code, notes, and snippets.

@stefansedich
Created March 15, 2012 01:52
Show Gist options
  • Select an option

  • Save stefansedich/2041158 to your computer and use it in GitHub Desktop.

Select an option

Save stefansedich/2041158 to your computer and use it in GitHub Desktop.
[Test]
public void Foo()
{
var initialList = new List<int>();
var list1 = new List<int>();
var list2 = new List<int>();
for(var i = 0; i < 100000; i++)
{
initialList.Add(i);
}
var sw1 = Stopwatch.StartNew();
foreach(var item in initialList)
{
list1.Add(item);
}
sw1.Stop();
Console.WriteLine(sw1.Elapsed.ToString());
var sw2 = Stopwatch.StartNew();
list2.AddRange(initialList);
sw2.Stop();
Console.WriteLine(sw2.Elapsed.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment