answer #1950 using BDN (#1951)

This commit is contained in:
Marc Gravell
2023-08-21 11:29:37 +01:00
committed by GitHub
parent 67f7a1fe17
commit ff98f8dbf1
4 changed files with 42 additions and 3 deletions
@@ -10,7 +10,7 @@ using System.ComponentModel;
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;
@@ -9,7 +9,7 @@ using System.Linq;
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;
@@ -3,7 +3,7 @@
<AssemblyName>Dapper.Tests.Performance</AssemblyName>
<Description>Dapper Core Performance Suite</Description>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net462;net5.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<NoWarn>$(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060</NoWarn>
</PropertyGroup>
@@ -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<Foo>(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.None));
[Benchmark]
public void QueryFirstParameters_Cache() => _connection.QueryFirst<Foo>(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<Foo>(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.NoCache));
[Benchmark]
public void QueryFirstParameters_NoCache() => _connection.QueryFirst<Foo>(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.NoCache));
}
}