Skip to content

Commit

Permalink
answer #1950 using BDN
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Aug 21, 2023
1 parent 67f7a1f commit d5b0928
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2DB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
39 changes: 39 additions & 0 deletions benchmarks/Dapper.Tests.Performance/DapperCacheImpact.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit d5b0928

Please sign in to comment.