Skip to content

Commit d38bb19

Browse files
Merge pull request #14 from pluskal/extendedbenchmarks
Extend benchmarks to demonstrate scalability
2 parents ceba517 + 20dba08 commit d38bb19

6 files changed

Lines changed: 152 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,5 @@ FakesAssemblies/
207207

208208
log-*.txt
209209

210-
docs/_build/
210+
docs/_build/
211+
/src/EFCore.Cassandra.Benchmarks/BenchmarkDotNet.Artifacts/results
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using BenchmarkDotNet.Attributes;
6+
using EFCore.Cassandra.Benchmarks.Models;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace EFCore.Cassandra.Benchmarks
10+
{
11+
[Config(typeof(CassandraBenchmarkConfig))]
12+
public class BatchedInsertData : IDisposable
13+
{
14+
private readonly FakeDbContext _dbContext;
15+
private Applicant[][] _applicants;
16+
17+
public BatchedInsertData()
18+
{
19+
_dbContext = new FakeDbContext();
20+
}
21+
22+
[ParamsSource(nameof(IterationsSource))]
23+
public int Iterations { get; set; } = 1000;
24+
25+
public IEnumerable<int> IterationsSource => new[] {1, 10, 100};
26+
27+
[ParamsSource(nameof(BatchSizeSource))]
28+
public int BatchSize { get; set; } = 10;
29+
30+
public IEnumerable<int> BatchSizeSource => new[] {10, 100};
31+
32+
public void Dispose()
33+
{
34+
_dbContext.Dispose();
35+
}
36+
37+
[GlobalSetup]
38+
public void SetupFixture()
39+
{
40+
_applicants = Enumerable.Range(0, Iterations).Select(_ => BuildApplicants()).ToArray();
41+
}
42+
43+
44+
[Benchmark]
45+
public async Task BatchedInsertApplicantsAsync()
46+
{
47+
var a = Enumerable.Range(0, Iterations)
48+
.Select(i => _dbContext.BulkInsertAsync(_applicants[i].ToList()));
49+
50+
await Task.WhenAll(a);
51+
}
52+
53+
54+
private Applicant[] BuildApplicants()
55+
{
56+
return Enumerable.Range(0, BatchSize).Select(_ => BuildApplicant()).ToArray();
57+
}
58+
59+
private static Applicant BuildApplicant() =>
60+
new Applicant
61+
{
62+
Id = Guid.NewGuid(),
63+
Order = 0,
64+
Dic = new Dictionary<string, string>(),
65+
Lst = new List<string>(),
66+
LstInt = new List<int>()
67+
};
68+
}
69+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Diagnosers;
4+
using BenchmarkDotNet.Environments;
5+
using BenchmarkDotNet.Jobs;
6+
7+
namespace EFCore.Cassandra.Benchmarks
8+
{
9+
[Config(typeof(CassandraBenchmarkConfig))]
10+
public class CassandraBenchmarkConfig : ManualConfig
11+
{
12+
public CassandraBenchmarkConfig()
13+
{
14+
AddJob(
15+
Job.Default
16+
.WithPlatform(Platform.X64)
17+
.WithJit(Jit.RyuJit)
18+
.WithRuntime(CoreRuntime.Core31)
19+
.WithWarmupCount(1)
20+
.WithIterationCount(3)
21+
.WithId("Cassandra benchmark config"));
22+
23+
AddDiagnoser(MemoryDiagnoser.Default);
24+
}
25+
}
26+
}

src/EFCore.Cassandra.Benchmarks/InsertData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace EFCore.Cassandra.Benchmarks
1111
{
12+
[Config(typeof(CassandraBenchmarkConfig))]
1213
public class InsertData : IDisposable
1314
{
1415
private readonly FakeDbContext _dbContext;

src/EFCore.Cassandra.Benchmarks/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ internal class Program
99
{
1010
private static async Task Main(string[] args)
1111
{
12+
#if DEBUG
13+
var insertData = new InsertData();
14+
insertData.AddApplicants();
15+
insertData.BulkInsertApplicants();
16+
insertData.AddRangeApplicants();
17+
18+
var batchedInsertData = new BatchedInsertData();
19+
await batchedInsertData.BatchedInsertApplicantsAsync();
20+
#else
1221
BenchmarkRunner.Run<InsertData>();
22+
BenchmarkRunner.Run<BatchedInsertData>();
23+
#endif
1324
}
1425
}
1526
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Benchmark results
2+
3+
## InsertData
4+
5+
```
6+
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
7+
AMD Ryzen 5 2600X, 1 CPU, 12 logical and 6 physical cores
8+
.NET Core SDK=5.0.100-rc.2.20479.15
9+
[Host] : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64 RyuJIT
10+
Cassandra benchmark config : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64 RyuJIT
11+
12+
Job=Cassandra benchmark config Jit=RyuJit Platform=X64
13+
Runtime=.NET Core 3.1 IterationCount=3 WarmupCount=1
14+
15+
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
16+
|--------------------- |---------:|----------:|---------:|------:|------:|------:|-----------:|
17+
| AddApplicants | 64.82 ms | 53.485 ms | 2.932 ms | - | - | - | 1632.24 KB |
18+
| AddRangeApplicants | 65.13 ms | 46.057 ms | 2.525 ms | - | - | - | 1634.05 KB |
19+
| BulkInsertApplicants | 29.42 ms | 5.828 ms | 0.319 ms | - | - | - | 556.35 KB |
20+
```
21+
22+
23+
# BarchedInsertData
24+
25+
```
26+
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
27+
AMD Ryzen 5 2600X, 1 CPU, 12 logical and 6 physical cores
28+
.NET Core SDK=5.0.100-rc.2.20479.15
29+
[Host] : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64 RyuJIT
30+
Cassandra benchmark config : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64 RyuJIT
31+
32+
Job=Cassandra benchmark config Jit=RyuJit Platform=X64
33+
Runtime=.NET Core 3.1 IterationCount=3 WarmupCount=1
34+
35+
| Method | Iterations | BatchSize | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
36+
|----------------------------- |----------- |---------- |-------------:|-----------:|----------:|-----------:|----------:|------:|-------------:|
37+
| BatchedInsertApplicantsAsync | 1 | 10 | 17.98 ms | 8.822 ms | 0.484 ms | - | - | - | 282.18 KB |
38+
| BatchedInsertApplicantsAsync | 1 | 100 | 134.66 ms | 133.414 ms | 7.313 ms | - | - | - | 2731.55 KB |
39+
| BatchedInsertApplicantsAsync | 10 | 10 | 138.43 ms | 78.095 ms | 4.281 ms | - | - | - | 2795.91 KB |
40+
| BatchedInsertApplicantsAsync | 10 | 100 | 1,186.80 ms | 99.393 ms | 5.448 ms | 5000.0000 | 1000.0000 | - | 25882.28 KB |
41+
| BatchedInsertApplicantsAsync | 100 | 10 | 1,227.66 ms | 75.714 ms | 4.150 ms | 6000.0000 | 1000.0000 | - | 26384.59 KB |
42+
| BatchedInsertApplicantsAsync | 100 | 100 | 11,802.71 ms | 582.269 ms | 31.916 ms | 63000.0000 | 2000.0000 | - | 258819.98 KB |
43+
```

0 commit comments

Comments
 (0)