Created
December 31, 2021 11:57
-
-
Save borakasmer/acb5d9bf307d5457240590015d627c48 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 async Task Main(string[] args) | |
{ | |
var summary = BenchmarkRunner.Run<ArrayVsList>(); | |
} | |
} | |
[MemoryDiagnoser] | |
public class ArrayVsList | |
{ | |
[Params(20, 80, 300, 800)] | |
public int capacity; | |
[Benchmark] | |
public int[] ArraySquidlist() | |
{ | |
var playerArray = new int[capacity]; | |
for(var i = 0; i < capacity; i++) | |
{ | |
playerArray[i] = i; | |
} | |
return playerArray; | |
} | |
[Benchmark] | |
public List<int> ListSquidlist() | |
{ | |
List<int> playerList = new List<int>(capacity); | |
for (var i = 0; i < capacity; i++) | |
{ | |
playerList.Add(i); | |
} | |
return playerList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment