Create a gist now

Instantly share code, notes, and snippets.

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