using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Reports; using System.Collections.Generic; using System.Linq; namespace Benchmarks { [Config(typeof(Config))] [HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)] [SimpleJob(RuntimeMoniker.Net90)] [MemoryDiagnoser] [ReturnValueValidator(failOnError: true)] [Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.SlowestToFastest)] public class GetRangeBenchmark { private List _userIds; [GlobalSetup] public void Setup() { _userIds = Enumerable.Range(1, 1000).Select(i => $"User{i}").ToList(); } [Benchmark(Baseline = true)] public List SkipAndTake() { return _userIds.Skip(200).Take(200).ToList(); } [Benchmark] public List Take() { return _userIds.Take(200..400).ToList(); } [Benchmark] public List GetRangeMethod() { return _userIds.GetRange(200, 200); } private class Config : ManualConfig { public Config() { SummaryStyle = SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend); } } } }