Skip to content

Instantly share code, notes, and snippets.

@rmaclean
Created May 20, 2016 10:12
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 rmaclean/611951ed1a6ef90a781a22190fb0af2e to your computer and use it in GitHub Desktop.
Save rmaclean/611951ed1a6ef90a781a22190fb0af2e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
namespace ConsoleApplication2
{
public class ListPerformance
{
const int size = 100000;
[Benchmark]
public void DefaultConstructorUsed()
{
var list = new List<int>();
for (int i = 0; i < size; i++)
{
list.Add(i);
}
}
[Benchmark]
public void ConstructorWithSizeUsed()
{
var list = new List<int>(size);
for (int i = 0; i < size; i++)
{
list.Add(i);
}
}
}
class Program
{
static void Main(string[] args)
{
BenchmarkDotNet.Running.BenchmarkRunner.Run<ListPerformance>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment