From d5b092821e80541f27745f739e0e8b7cdcd0f1e5 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Mon, 21 Aug 2023 11:29:12 +0100 Subject: [PATCH] answer #1950 using BDN --- .../Benchmarks.Linq2DB.cs | 2 +- .../Benchmarks.Linq2Sql.cs | 2 +- .../Dapper.Tests.Performance.csproj | 2 +- .../DapperCacheImpact.cs | 39 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 benchmarks/Dapper.Tests.Performance/DapperCacheImpact.cs diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs index ef2610183..cb9aaacd2 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs @@ -10,7 +10,7 @@ namespace Dapper.Tests.Performance { [Description("LINQ to DB")] - public class Linq2DBBenchmarks : BenchmarkBase + public class LinqToDBBenchmarks : BenchmarkBase // note To not 2 because the "2" confuses BDN CLI { private Linq2DBContext _dbContext; diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs index dcee70577..d6cc55049 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs @@ -9,7 +9,7 @@ namespace Dapper.Tests.Performance { [Description("LINQ to SQL")] - public class Linq2SqlBenchmarks : BenchmarkBase + public class LinqToSqlBenchmarks : BenchmarkBase // note To not 2 because the "2" confuses BDN CLI { private DataClassesDataContext Linq2SqlContext; diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index a9b419994..0a7f71582 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -3,7 +3,7 @@ Dapper.Tests.Performance Dapper Core Performance Suite Exe - net462;netcoreapp3.1 + net462;net5.0 false $(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060 diff --git a/benchmarks/Dapper.Tests.Performance/DapperCacheImpact.cs b/benchmarks/Dapper.Tests.Performance/DapperCacheImpact.cs new file mode 100644 index 000000000..9e17249bf --- /dev/null +++ b/benchmarks/Dapper.Tests.Performance/DapperCacheImpact.cs @@ -0,0 +1,39 @@ +using System.ComponentModel; +using BenchmarkDotNet.Attributes; + +namespace Dapper.Tests.Performance +{ + [Description("Dapper cache impact")] + [MemoryDiagnoser] + public class DapperCacheImpact : BenchmarkBase + { + [GlobalSetup] + public void Setup() => BaseSetup(); + + private object args = new { Id = 42, Name = "abc" }; + + public class Foo + { + public int Id { get; set; } + public string Name { get; set; } + } + + // note: custom BDN setup means [Params] is awkward; unroll manually instead + [Benchmark] + public void ExecuteNoParameters_Cache() => _connection.Execute(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.None)); + [Benchmark] + public void ExecuteParameters_Cache() => _connection.Execute(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.None)); + [Benchmark] + public void QueryFirstNoParameters_Cache() => _connection.QueryFirst(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.None)); + [Benchmark] + public void QueryFirstParameters_Cache() => _connection.QueryFirst(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.None)); + [Benchmark] + public void ExecuteNoParameters_NoCache() => _connection.Execute(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.NoCache)); + [Benchmark] + public void ExecuteParameters_NoCache() => _connection.Execute(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.NoCache)); + [Benchmark] + public void QueryFirstNoParameters_NoCache() => _connection.QueryFirst(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.NoCache)); + [Benchmark] + public void QueryFirstParameters_NoCache() => _connection.QueryFirst(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.NoCache)); + } +}