Skip to content

Instantly share code, notes, and snippets.

@davepcallan
Created September 18, 2022 21:10
Show Gist options
  • Save davepcallan/65aaa5d7baa40caafd370824df419656 to your computer and use it in GitHub Desktop.
Save davepcallan/65aaa5d7baa40caafd370824df419656 to your computer and use it in GitHub Desktop.
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