Skip to content

Commit 6bd52bd

Browse files
Merge pull request #517 from johelvisguzman/benchmark
Updated the benchmarks
2 parents 6ffe2ba + 598c474 commit 6bd52bd

9 files changed

+112
-170
lines changed

benchmarks/DotNetToolkit.Repository.Performance/Benchmarks.Config.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Config()
1919
Add(CsvExporter.Default);
2020
Add(MarkdownExporter.GitHub);
2121
Add(HtmlExporter.Default);
22-
Add(new MemoryDiagnoser());
22+
Add(MemoryDiagnoser.Default);
2323
Add(new ProviderColumn());
2424
Add(TargetMethodColumn.Method);
2525
Add(StatisticColumn.Mean);
@@ -34,9 +34,8 @@ public Config()
3434
.With(InProcessToolchain.Instance)
3535
);
3636

37-
Set(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest));
38-
39-
SummaryPerType = false;
37+
Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest);
38+
Options = ConfigOptions.JoinSummary;
4039
}
4140
}
4241
}

benchmarks/DotNetToolkit.Repository.Performance/Benchmarks.Repository.Add.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
{
33
using BenchmarkDotNet.Attributes;
44
using Data;
5-
using System.Threading.Tasks;
65

7-
[BenchmarkCategory("RepositoryTraits")]
6+
[BenchmarkCategory("Add")]
87
public class Repository_Add_Benchmarks : BenchmarkBase
98
{
109
private IRepository<Customer> _repo;
@@ -26,28 +25,16 @@ public void Clean()
2625
_repo.Delete(x => x.Id != 0);
2726
}
2827

29-
[BenchmarkCategory("Add"), Benchmark]
28+
[Benchmark]
3029
public void Add()
3130
{
3231
_repo.Add(_customer);
3332
}
3433

35-
[BenchmarkCategory("AddRange"), Benchmark]
34+
[Benchmark]
3635
public void AddRange()
3736
{
3837
_repo.Add(new[] { _customer });
3938
}
40-
41-
[BenchmarkCategory("AddAsync"), Benchmark]
42-
public async Task Async_Add()
43-
{
44-
await _repo.AddAsync(_customer);
45-
}
46-
47-
[BenchmarkCategory("AddRangeAsync"), Benchmark]
48-
public async Task Async_AddRange()
49-
{
50-
await _repo.AddAsync(new[] { _customer });
51-
}
5239
}
5340
}

benchmarks/DotNetToolkit.Repository.Performance/Benchmarks.Repository.Delete.cs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
{
33
using BenchmarkDotNet.Attributes;
44
using Data;
5-
using System.Threading.Tasks;
65

7-
[BenchmarkCategory("RepositoryTraits")]
6+
[BenchmarkCategory("Delete")]
87
public class Repository_Delete_Benchmarks : BenchmarkBase
98
{
109
private IRepository<Customer> _repo;
@@ -27,52 +26,28 @@ public void Clean()
2726
_repo.Delete(x => x.Id != 0);
2827
}
2928

30-
[BenchmarkCategory("Delete"), Benchmark]
29+
[Benchmark]
3130
public void Delete()
3231
{
3332
_repo.Delete(_customer);
3433
}
3534

36-
[BenchmarkCategory("DeleteRange"), Benchmark]
35+
[Benchmark]
3736
public void DeleteRange()
3837
{
3938
_repo.Delete(new[] { _customer });
4039
}
4140

42-
[BenchmarkCategory("DeleteWithId"), Benchmark]
41+
[Benchmark]
4342
public void DeleteWithId()
4443
{
4544
_repo.Delete(_customer.Id);
4645
}
4746

48-
[BenchmarkCategory("DeleteWithPredicate"), Benchmark]
47+
[Benchmark]
4948
public void DeleteWithPredicate()
5049
{
5150
_repo.Delete(x => x.Id == _customer.Id);
5251
}
53-
54-
[BenchmarkCategory("DeleteAsync"), Benchmark]
55-
public async Task Async_Delete()
56-
{
57-
await _repo.DeleteAsync(_customer);
58-
}
59-
60-
[BenchmarkCategory("DeleteRangeAsync"), Benchmark]
61-
public async Task Async_DeleteRange()
62-
{
63-
await _repo.DeleteAsync(new[] { _customer });
64-
}
65-
66-
[BenchmarkCategory("DeleteWithIdAsync"), Benchmark]
67-
public async Task Async_DeleteWithId()
68-
{
69-
await _repo.DeleteAsync(_customer.Id);
70-
}
71-
72-
[BenchmarkCategory("DeleteWithPredicateAsync"), Benchmark]
73-
public async Task Async_DeleteWithPredicate()
74-
{
75-
await _repo.DeleteAsync(x => x.Id == _customer.Id);
76-
}
7752
}
7853
}

benchmarks/DotNetToolkit.Repository.Performance/Benchmarks.Repository.Find.cs

Lines changed: 8 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
using BenchmarkDotNet.Attributes;
44
using Data;
55
using Queries;
6-
using System.Threading.Tasks;
76

8-
[BenchmarkCategory("RepositoryTraits")]
7+
[BenchmarkCategory("Find")]
98
public class Repository_Find_Benchmarks : BenchmarkBase
109
{
1110
private IRepository<Customer> _repo;
@@ -29,136 +28,46 @@ public void Setup()
2928
_repo.Add(_customer);
3029
}
3130

32-
[BenchmarkCategory("FindWithId"), Benchmark]
31+
[Benchmark]
3332
public void FindWithId()
3433
{
3534
_repo.Find(_customer.Id);
3635
}
3736

38-
[BenchmarkCategory("FindWithPredicate"), Benchmark]
37+
[Benchmark]
3938
public void FindWithPredicate()
4039
{
4140
_repo.Find(x => x.Name.Equals("Random Name"));
4241
}
4342

44-
[BenchmarkCategory("FindWithPredicateOptions"), Benchmark]
43+
[Benchmark]
4544
public void FindWithPredicateOptions()
4645
{
4746
_repo.Find(_defaultOptions);
4847
}
4948

50-
[BenchmarkCategory("FindWithPagingOptions"), Benchmark]
49+
[Benchmark]
5150
public void FindWithPagingOptions()
5251
{
5352
_repo.Find(_pagingOptions);
5453
}
5554

56-
[BenchmarkCategory("FindAllWithPredicate"), Benchmark]
55+
[Benchmark]
5756
public void FindAllWithPredicate()
5857
{
5958
_repo.FindAll(x => x.Name.Equals("Random Name"));
6059
}
6160

62-
[BenchmarkCategory("FindAllWithPredicateOptions"), Benchmark]
61+
[Benchmark]
6362
public void FindAllWithPredicateOptions()
6463
{
6564
_repo.FindAll(_defaultOptions);
6665
}
6766

68-
[BenchmarkCategory("FindAllWithPagingOptions"), Benchmark]
67+
[Benchmark]
6968
public void FindAllWithPagingOptions()
7069
{
7170
_repo.FindAll(_pagingOptions);
7271
}
73-
74-
[BenchmarkCategory("ToDictionaryWithPredicateOptions"), Benchmark]
75-
public void ToDictionaryWithPredicateOptions()
76-
{
77-
_repo.ToDictionary(_defaultOptions, x => x.Id);
78-
}
79-
80-
[BenchmarkCategory("ToDictionaryWithPagingOptions"), Benchmark]
81-
public void ToDictionaryWithPagingOptions()
82-
{
83-
_repo.ToDictionary(_pagingOptions, x => x.Id);
84-
}
85-
86-
[BenchmarkCategory("GroupByWithPredicateOptions"), Benchmark]
87-
public void GroupByWithPredicateOptions()
88-
{
89-
_repo.GroupBy(_defaultOptions, y => y.Id, (key, g) => key);
90-
}
91-
92-
[BenchmarkCategory("GroupByWithPagingOptions"), Benchmark]
93-
public void GroupByWithPagingOptions()
94-
{
95-
_repo.GroupBy(_pagingOptions, y => y.Id, (key, g) => key);
96-
}
97-
98-
[BenchmarkCategory("FindWithIdAsync"), Benchmark]
99-
public async Task Async_FindWithId()
100-
{
101-
await _repo.FindAsync(_customer.Id);
102-
}
103-
104-
[BenchmarkCategory("FindWithPredicateAsync"), Benchmark]
105-
public async Task Async_FindWithPredicate()
106-
{
107-
await _repo.FindAsync(x => x.Name.Equals("Random Name"));
108-
}
109-
110-
[BenchmarkCategory("FindWithPreicateOptionsAsync"), Benchmark]
111-
public async Task Async_FindWithPreicateOptions()
112-
{
113-
await _repo.FindAsync(_defaultOptions);
114-
}
115-
116-
[BenchmarkCategory("FindWithPagingOptionsAsync"), Benchmark]
117-
public async Task Async_FindWithPagingOptions()
118-
{
119-
await _repo.FindAsync(_pagingOptions);
120-
}
121-
122-
[BenchmarkCategory("FindAllWithPredicateAsync"), Benchmark]
123-
public async Task Async_FindAllWithPredicate()
124-
{
125-
await _repo.FindAllAsync(x => x.Name.Equals("Random Name"));
126-
}
127-
128-
[BenchmarkCategory("FindAllWithPredicateOptionsAsync"), Benchmark]
129-
public async Task Async_FindAllWithPredicateOptions()
130-
{
131-
await _repo.FindAllAsync(_defaultOptions);
132-
}
133-
134-
[BenchmarkCategory("FindAllWithPagingOptionsAsync"), Benchmark]
135-
public async Task Async_FindAllWithPagingOptions()
136-
{
137-
await _repo.FindAllAsync(_pagingOptions);
138-
}
139-
140-
[BenchmarkCategory("GroupByWithPredicateOptionsAsync"), Benchmark]
141-
public async Task Async_GroupByWithPredicateOptions()
142-
{
143-
await _repo.GroupByAsync(_defaultOptions, y => y.Id, (key, g) => key);
144-
}
145-
146-
[BenchmarkCategory("GroupByWithPagingOptionsAsync"), Benchmark]
147-
public async Task Async_GroupByWithPagingOptions()
148-
{
149-
await _repo.GroupByAsync(_pagingOptions, y => y.Id, (key, g) => key);
150-
}
151-
152-
[BenchmarkCategory("ToDictionaryWithPredicateOptionsAsync"), Benchmark]
153-
public async Task Async_ToDictionaryWithPredicateOptions()
154-
{
155-
await _repo.ToDictionaryAsync(_defaultOptions, x => x.Id);
156-
}
157-
158-
[BenchmarkCategory("ToDictionaryWithPagingOptionsAsync"), Benchmark]
159-
public async Task Async_ToDictionaryWithPagingOptions()
160-
{
161-
await _repo.ToDictionaryAsync(_pagingOptions, x => x.Id);
162-
}
16372
}
16473
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace DotNetToolkit.Repository.Performance
2+
{
3+
using BenchmarkDotNet.Attributes;
4+
using Data;
5+
using Queries;
6+
7+
[BenchmarkCategory("GroupBy")]
8+
public class Repository_GroupBy_Benchmarks : BenchmarkBase
9+
{
10+
private IRepository<Customer> _repo;
11+
private Customer _customer;
12+
private QueryOptions<Customer> _defaultOptions;
13+
private QueryOptions<Customer> _pagingOptions;
14+
15+
[GlobalSetup]
16+
public void Setup()
17+
{
18+
BaseSetup();
19+
20+
_defaultOptions = new QueryOptions<Customer>()
21+
.SatisfyBy(x => x.Name.Equals("Random Name"));
22+
23+
_pagingOptions = _defaultOptions.Page(1, 10);
24+
25+
_customer = new Customer { Name = "Random Name" };
26+
27+
_repo = new Repository<Customer>(BuildOptions(Provider));
28+
_repo.Add(_customer);
29+
}
30+
31+
[Benchmark]
32+
public void GroupByWithPredicateOptions()
33+
{
34+
_repo.GroupBy(_defaultOptions, y => y.Id, (key, g) => key);
35+
}
36+
37+
[Benchmark]
38+
public void GroupByWithPagingOptions()
39+
{
40+
_repo.GroupBy(_pagingOptions, y => y.Id, (key, g) => key);
41+
}
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace DotNetToolkit.Repository.Performance
2+
{
3+
using BenchmarkDotNet.Attributes;
4+
using Data;
5+
using Queries;
6+
7+
[BenchmarkCategory("ToDictionary")]
8+
public class Repository_ToDictionary_Benchmarks : BenchmarkBase
9+
{
10+
private IRepository<Customer> _repo;
11+
private Customer _customer;
12+
private QueryOptions<Customer> _defaultOptions;
13+
private QueryOptions<Customer> _pagingOptions;
14+
15+
[GlobalSetup]
16+
public void Setup()
17+
{
18+
BaseSetup();
19+
20+
_defaultOptions = new QueryOptions<Customer>()
21+
.SatisfyBy(x => x.Name.Equals("Random Name"));
22+
23+
_pagingOptions = _defaultOptions.Page(1, 10);
24+
25+
_customer = new Customer { Name = "Random Name" };
26+
27+
_repo = new Repository<Customer>(BuildOptions(Provider));
28+
_repo.Add(_customer);
29+
}
30+
31+
[Benchmark]
32+
public void ToDictionaryWithPredicateOptions()
33+
{
34+
_repo.ToDictionary(_defaultOptions, x => x.Id);
35+
}
36+
37+
[Benchmark]
38+
public void ToDictionaryWithPagingOptions()
39+
{
40+
_repo.ToDictionary(_pagingOptions, x => x.Id);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)