Skip to content

Instantly share code, notes, and snippets.

@borakasmer
Created December 31, 2021 11:57
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/acb5d9bf307d5457240590015d627c48 to your computer and use it in GitHub Desktop.
Save borakasmer/acb5d9bf307d5457240590015d627c48 to your computer and use it in GitHub Desktop.
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