-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathBenchmarks.RepoDB.cs
More file actions
67 lines (59 loc) · 2.03 KB
/
Benchmarks.RepoDB.cs
File metadata and controls
67 lines (59 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.ComponentModel;
using System.Linq;
using BenchmarkDotNet.Attributes;
using RepoDb;
using RepoDb.DbHelpers;
using RepoDb.DbSettings;
using RepoDb.StatementBuilders;
namespace Dapper.Tests.Performance
{
[Description("RepoDB")]
public class RepoDbBenchmarks : BenchmarkBase
{
[GlobalSetup]
public void Setup()
{
BaseSetup();
GlobalConfiguration.Setup().UseSqlServer();
// We need this since benchmarks using System.Data.SqlClient
var dbSetting = new SqlServerDbSetting();
DbSettingMapper
.Add<Microsoft.Data.SqlClient.SqlConnection>(dbSetting, true);
DbHelperMapper
.Add<Microsoft.Data.SqlClient.SqlConnection>(new SqlServerDbHelper(), true);
StatementBuilderMapper
.Add<Microsoft.Data.SqlClient.SqlConnection>(new SqlServerStatementBuilder(dbSetting), true);
ClassMapper.Add<Post>("Posts");
}
[Benchmark(Description = "Query<T>")]
public Post Query()
{
Step();
return _connection.Query<Post>(i).First();
}
[Benchmark(Description = "QueryWhere<T>")]
public Post QueryWhere()
{
Step();
return _connection.Query<Post>(x => x.Id == i).First();
}
[Benchmark(Description = "QueryDynamic<T>")]
public Post QueryDynamic()
{
Step();
return _connection.Query<Post>(new { Id = i }).First();
}
[Benchmark(Description = "QueryField<T>")]
public Post QueryField()
{
Step();
return _connection.Query<Post>([new(nameof(Post.Id), i)]).First();
}
[Benchmark(Description = "ExecuteQuery<T>")]
public Post ExecuteQuery()
{
Step();
return _connection.ExecuteQuery<Post>("select * from Posts where Id = @Id", new { Id = i }).First();
}
}
}