Last active
February 8, 2024 19:00
-
-
Save davepcallan/1587a9b24e0adbf0f33378ff8506f2a7 to your computer and use it in GitHub Desktop.
.NET 8 v .NET 9 LINQ benchmarks
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.Configs; | |
using BenchmarkDotNet.Environments; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Reports; | |
namespace Benchmarks | |
{ | |
[Config(typeof(Config))] | |
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)] | |
[MemoryDiagnoser] | |
public class Linq | |
{ | |
[Params(50)] | |
public int Length { get; set; } | |
private IEnumerable<int> _source, _sourceToCompare; | |
[GlobalSetup] | |
public void Setup() | |
{ | |
_source = Enumerable.Range(1, Length).ToArray(); | |
_sourceToCompare = Enumerable.Range(1, Length).ToArray(); | |
} | |
[Benchmark] | |
public int Min() => _source.Min(); | |
[Benchmark] | |
public int Max() => _source.Max(); | |
[Benchmark] | |
public int Count() => _source.Count(); | |
[Benchmark] | |
public int ElementAt() => _source.ElementAt(5); | |
[Benchmark] | |
public bool SequenceEqual() => | |
_source.SequenceEqual(_sourceToCompare); | |
private class Config : ManualConfig | |
{ | |
public Config() | |
{ | |
AddJob(Job.Default.WithId(".NET 8").WithRuntime(CoreRuntime.Core80).AsBaseline()); | |
AddJob(Job.Default.WithId(".NET 9").WithRuntime(CoreRuntime.Core90)); | |
SummaryStyle = | |
SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment