Created
December 31, 2021 10:49
-
-
Save borakasmer/0c8de77a401a737efd033f644d628e22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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