-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathSelectsBenchmark.cs
82 lines (68 loc) · 2.22 KB
/
SelectsBenchmark.cs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
using QueryBuilder.Benchmarks.Infrastructure;
using SqlKata;
using SqlKata.Compilers;
namespace QueryBuilder.Benchmarks;
[MemoryDiagnoser]
public class SelectsBenchmark
{
private Query selectSimple;
private Query selectGroupBy;
private Query selectWith;
public Compiler compiler;
[Params(
EngineCodes.SqlServer)]
public string EngineCode { get; set; }
[GlobalSetup]
public void Setup()
{
selectSimple = new Query("Products")
.Select("ProductID", "ProductName", "SupplierID", "CategoryID", "UnitPrice", "UnitsInStock", "UnitsOnOrder",
"ReorderLevel", "Discontinued")
.WhereIn("CategoryID", [1, 2, 3])
.Where("SupplierID", 5)
.Where("UnitPrice", ">=", 10)
.Where("UnitPrice", "<=", 100)
.Take(10)
.Skip(20)
.OrderBy("UnitPrice", "ProductName");
selectGroupBy = new Query("Products")
.Select("SupplierID", "CategoryID")
.SelectAvg("UnitPrice")
.SelectMin("UnitPrice")
.SelectMax("UnitPrice")
.Where("CategoryID", 123)
.GroupBy("SupplierID", "CategoryID")
.HavingRaw("MIN(UnitPrice) >= ?", 10)
.Take(10)
.Skip(20)
.OrderBy("SupplierID", "CategoryID");
var activePosts = new Query("Comments")
.Select("PostId")
.SelectRaw("count(1) as Count")
.GroupBy("PostId")
.HavingRaw("count(1) > 100");
selectWith = new Query("Posts")
.With("ActivePosts", activePosts)
.Join("ActivePosts", "ActivePosts.PostId", "Posts.Id")
.Select("Posts.*", "ActivePosts.Count");
compiler = TestSupport.CreateCompiler(EngineCode);
}
[Benchmark]
public SqlResult SelectSimple()
{
return compiler.Compile(selectSimple);
}
[Benchmark]
public SqlResult SelectGroupBy()
{
return compiler.Compile(selectGroupBy);
}
[Benchmark]
public SqlResult SelectWith()
{
return compiler.Compile(selectWith);
}
}