Skip to content

Instantly share code, notes, and snippets.

@sa-es-ir
Created April 25, 2024 16:20
Show Gist options
  • Save sa-es-ir/5aa72aaa58b953979e5f38fcaf705782 to your computer and use it in GitHub Desktop.
Save sa-es-ir/5aa72aaa58b953979e5f38fcaf705782 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
namespace Benchmarks;
[MemoryDiagnoser(false)]
[HideColumns(Column.RatioSD, Column.AllocRatio)]
[SimpleJob(RuntimeMoniker.Net80)]
public class ListCountBenchmark
{
private List<int> _list;
[Params(1_000_000)]
public int Count { get; set; }
[GlobalSetup]
public void GlobalSetup()
{
IEnumerable<int> range = Enumerable.Range(0, Count);
_list = range.ToList();
}
[Benchmark]
public int ListCountMethod() => _list.Count();
[Benchmark]
public int ListCountProperty() => _list.Count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment