Created
April 25, 2024 16:20
-
-
Save sa-es-ir/5aa72aaa58b953979e5f38fcaf705782 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.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