Created
September 18, 2022 21:10
-
-
Save davepcallan/65aaa5d7baa40caafd370824df419656 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 System.Collections.Generic; | |
using System.Linq; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Columns; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Reports; | |
namespace BenchmarkDotNet.Samples | |
{ | |
[Config(typeof(Config))] | |
[SimpleJob(RuntimeMoniker.Net60, baseline:true)] | |
[SimpleJob(RuntimeMoniker.Net70)] | |
public class LINQBenchmarks | |
{ | |
[Params(1000)] | |
public int Length { get; set; } | |
private IEnumerable<int> _source; | |
[GlobalSetup] | |
public void Setup() => _source = Enumerable.Range(1, Length).ToArray(); | |
[Benchmark] | |
public int Min() => _source.Min(); | |
[Benchmark] | |
public int Max() => _source.Max(); | |
[Benchmark] | |
public float Sum() => _source.Sum(); | |
[Benchmark] | |
public double Average() => _source.Average(); | |
private class Config : ManualConfig | |
{ | |
public Config() | |
{ | |
SummaryStyle = | |
SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment