Skip to content

Instantly share code, notes, and snippets.

@sa-es-ir
Created May 8, 2024 03:46
Show Gist options
  • Save sa-es-ir/bfd1e7a2e245835334c6824a727121c4 to your computer and use it in GitHub Desktop.
Save sa-es-ir/bfd1e7a2e245835334c6824a727121c4 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using DatabaseNight.Context;
using System.Linq;
namespace DatabaseNight;
[Config(typeof(Config))]
[HideColumns(Column.RatioSD, Column.AllocRatio)]
[MemoryDiagnoser(false)]
public class EFTuningService
{
private class Config : ManualConfig
{
public Config()
{
SummaryStyle = SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend);
}
}
[Benchmark(Baseline = true)]
public bool Count()
{
var context = new ApplicationContext();
return context.Employees
.Count(x => x.DepartmentId == 7) > 0;
}
[Benchmark]
public bool Any()
{
var context = new ApplicationContext();
return context.Employees
.Any(x => x.DepartmentId == 7);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment