Skip to content

Instantly share code, notes, and snippets.

@borakasmer
Created December 31, 2021 10:49
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 borakasmer/0c8de77a401a737efd033f644d628e22 to your computer and use it in GitHub Desktop.
Save borakasmer/0c8de77a401a737efd033f644d628e22 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Program
{
public static void Main(string[] args)
{
var summary= BenchmarkRunner.Run<ListCapacityPerformance>();
}
}
[MemoryDiagnoser]
public class ListCapacityPerformance
{
[Params(20, 80, 300, 800)]
public int capacity;
[Benchmark]
public List<int> DynamicCapacity()
{
List<int> squidList = new List<int>();
for (int i = 0; i < capacity; i++)
{
squidList.Add(i);
}
return squidList;
}
[Benchmark]
public List<int> SetCapacity()
{
List<int> squidList = new List<int>(capacity);
for (int i = 0; i < capacity; i++)
{
squidList.Add(i);
}
return squidList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment