Skip to content

Commit ff98f8d

Browse files
authored
answer #1950 using BDN (#1951)
1 parent 67f7a1f commit ff98f8d

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Dapper.Tests.Performance
1111
{
1212
[Description("LINQ to DB")]
13-
public class Linq2DBBenchmarks : BenchmarkBase
13+
public class LinqToDBBenchmarks : BenchmarkBase // note To not 2 because the "2" confuses BDN CLI
1414
{
1515
private Linq2DBContext _dbContext;
1616

benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Dapper.Tests.Performance
1010
{
1111
[Description("LINQ to SQL")]
12-
public class Linq2SqlBenchmarks : BenchmarkBase
12+
public class LinqToSqlBenchmarks : BenchmarkBase // note To not 2 because the "2" confuses BDN CLI
1313
{
1414
private DataClassesDataContext Linq2SqlContext;
1515

benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<AssemblyName>Dapper.Tests.Performance</AssemblyName>
44
<Description>Dapper Core Performance Suite</Description>
55
<OutputType>Exe</OutputType>
6-
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
6+
<TargetFrameworks>net462;net5.0</TargetFrameworks>
77
<IsTestProject>false</IsTestProject>
88
<NoWarn>$(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060</NoWarn>
99
</PropertyGroup>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.ComponentModel;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace Dapper.Tests.Performance
5+
{
6+
[Description("Dapper cache impact")]
7+
[MemoryDiagnoser]
8+
public class DapperCacheImpact : BenchmarkBase
9+
{
10+
[GlobalSetup]
11+
public void Setup() => BaseSetup();
12+
13+
private object args = new { Id = 42, Name = "abc" };
14+
15+
public class Foo
16+
{
17+
public int Id { get; set; }
18+
public string Name { get; set; }
19+
}
20+
21+
// note: custom BDN setup means [Params] is awkward; unroll manually instead
22+
[Benchmark]
23+
public void ExecuteNoParameters_Cache() => _connection.Execute(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.None));
24+
[Benchmark]
25+
public void ExecuteParameters_Cache() => _connection.Execute(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.None));
26+
[Benchmark]
27+
public void QueryFirstNoParameters_Cache() => _connection.QueryFirst<Foo>(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.None));
28+
[Benchmark]
29+
public void QueryFirstParameters_Cache() => _connection.QueryFirst<Foo>(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.None));
30+
[Benchmark]
31+
public void ExecuteNoParameters_NoCache() => _connection.Execute(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.NoCache));
32+
[Benchmark]
33+
public void ExecuteParameters_NoCache() => _connection.Execute(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.NoCache));
34+
[Benchmark]
35+
public void QueryFirstNoParameters_NoCache() => _connection.QueryFirst<Foo>(new CommandDefinition("select '42' as Id, 'abc' as Name", flags: CommandFlags.NoCache));
36+
[Benchmark]
37+
public void QueryFirstParameters_NoCache() => _connection.QueryFirst<Foo>(new CommandDefinition("select @id as Id, @name as Name", args, flags: CommandFlags.NoCache));
38+
}
39+
}

0 commit comments

Comments
 (0)