Skip to content

Commit 01d401c

Browse files
committed
add explicit collection bulkwrite benchmarks
1 parent 729601a commit 01d401c

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

CSharpDriver.sln

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.Encryption.T
6060
EndProject
6161
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.Authentication.AWS", "src\MongoDB.Driver.Authentication.AWS\MongoDB.Driver.Authentication.AWS.csproj", "{A0CAC199-457E-4862-AF9E-971C7A77CBF9}"
6262
EndProject
63+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{54EBC539-ABFB-45A0-A77F-1A294576212B}"
64+
EndProject
6365
Global
6466
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6567
Debug|Any CPU = Debug|Any CPU
@@ -130,6 +132,10 @@ Global
130132
{A0CAC199-457E-4862-AF9E-971C7A77CBF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
131133
{A0CAC199-457E-4862-AF9E-971C7A77CBF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
132134
{A0CAC199-457E-4862-AF9E-971C7A77CBF9}.Release|Any CPU.Build.0 = Release|Any CPU
135+
{54EBC539-ABFB-45A0-A77F-1A294576212B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
136+
{54EBC539-ABFB-45A0-A77F-1A294576212B}.Debug|Any CPU.Build.0 = Debug|Any CPU
137+
{54EBC539-ABFB-45A0-A77F-1A294576212B}.Release|Any CPU.ActiveCfg = Release|Any CPU
138+
{54EBC539-ABFB-45A0-A77F-1A294576212B}.Release|Any CPU.Build.0 = Release|Any CPU
133139
EndGlobalSection
134140
GlobalSection(SolutionProperties) = preSolution
135141
HideSolutionNode = FALSE

benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/BulkWriteMixedOpsBenchmark.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public void BeforeTask()
6464
}
6565

6666
[Benchmark]
67-
public void SmallDocCollectionBulkMixedOpsBenchmark()
67+
public void SmallDocCollectionBulkWriteMixedOpsBenchmark()
6868
{
6969
_collection.BulkWrite(_collectionBulkWriteMixedOpsModels, new BulkWriteOptions());
7070
}
7171

7272
[Benchmark]
73-
public void SmallDocClientBulkMixedOpsBenchmark()
73+
public void SmallDocClientBulkWriteMixedOpsBenchmark()
7474
{
7575
_client.BulkWrite(_clientBulkWriteMixedOpsModels, new ClientBulkWriteOptions());
7676
}

benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/LargeDocBulkInsertBenchmark.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class LargeDocBulkInsertBenchmark
3030
private IMongoCollection<BsonDocument> _collection;
3131
private IMongoDatabase _database;
3232
private IEnumerable<BsonDocument> _largeDocuments;
33+
private List<InsertOneModel<BsonDocument>> _collectionBulkWriteInsertModels;
34+
private List<BulkWriteInsertOneModel<BsonDocument>> _clientBulkWriteInsertModels;
3335

3436
private static readonly CollectionNamespace __collectionNamespace =
3537
CollectionNamespace.FromFullName($"{MongoConfiguration.PerfTestDatabaseName}.{MongoConfiguration.PerfTestCollectionName}");
@@ -44,7 +46,9 @@ public void Setup()
4446
_database = _client.GetDatabase(MongoConfiguration.PerfTestDatabaseName);
4547

4648
var largeDocument = ReadExtendedJson("single_and_multi_document/large_doc.json");
47-
_largeDocuments = Enumerable.Range(0, 10).Select(_ => largeDocument.DeepClone().AsBsonDocument);
49+
_largeDocuments = Enumerable.Range(0, 10).Select(_ => largeDocument.DeepClone().AsBsonDocument).ToList();
50+
_collectionBulkWriteInsertModels = _largeDocuments.Select(x => new InsertOneModel<BsonDocument>(x.DeepClone().AsBsonDocument)).ToList();
51+
_clientBulkWriteInsertModels = _largeDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x.DeepClone().AsBsonDocument)).ToList();
4852
}
4953

5054
[IterationSetup]
@@ -61,10 +65,15 @@ public void InsertManyLargeBenchmark()
6165
}
6266

6367
[Benchmark]
64-
public void LargeDocClientBulkInsertBenchmark()
68+
public void LargeDocCollectionBulkWriteInsertBenchmark()
6569
{
66-
var models = _largeDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x)).ToList();
67-
_client.BulkWrite(models, new ClientBulkWriteOptions());
70+
_collection.BulkWrite(_collectionBulkWriteInsertModels, new BulkWriteOptions());
71+
}
72+
73+
[Benchmark]
74+
public void LargeDocClientBulkWriteInsertBenchmark()
75+
{
76+
_client.BulkWrite(_clientBulkWriteInsertModels, new ClientBulkWriteOptions());
6877
}
6978

7079
[GlobalCleanup]

benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/SmallDocBulkInsertBenchmark.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public class SmallDocBulkInsertBenchmark
2929
private IMongoClient _client;
3030
private IMongoCollection<BsonDocument> _collection;
3131
private IMongoDatabase _database;
32-
private IEnumerable<BsonDocument> _smallDocuments;
32+
private List<BsonDocument> _smallDocuments;
33+
private List<InsertOneModel<BsonDocument>> _collectionBulkWriteInsertModels;
34+
private List<BulkWriteInsertOneModel<BsonDocument>> _clientBulkWriteInsertModels;
3335

3436
private static readonly CollectionNamespace __collectionNamespace =
3537
CollectionNamespace.FromFullName($"{MongoConfiguration.PerfTestDatabaseName}.{MongoConfiguration.PerfTestCollectionName}");
@@ -44,7 +46,9 @@ public void Setup()
4446
_database = _client.GetDatabase(MongoConfiguration.PerfTestDatabaseName);
4547

4648
var smallDocument = ReadExtendedJson("single_and_multi_document/small_doc.json");
47-
_smallDocuments = Enumerable.Range(0, 10000).Select(_ => smallDocument.DeepClone().AsBsonDocument);
49+
_smallDocuments = Enumerable.Range(0, 10000).Select(_ => smallDocument.DeepClone().AsBsonDocument).ToList();
50+
_collectionBulkWriteInsertModels = _smallDocuments.Select(x => new InsertOneModel<BsonDocument>(x.DeepClone().AsBsonDocument)).ToList();
51+
_clientBulkWriteInsertModels = _smallDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x.DeepClone().AsBsonDocument)).ToList();
4852
}
4953

5054
[IterationSetup]
@@ -61,10 +65,15 @@ public void InsertManySmallBenchmark()
6165
}
6266

6367
[Benchmark]
64-
public void SmallDocClientBulkInsertBenchmark()
68+
public void SmallDocCollectionBulkWriteInsertBenchmark()
6569
{
66-
var models = _smallDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x)).ToList();
67-
_client.BulkWrite(models, new ClientBulkWriteOptions());
70+
_collection.BulkWrite(_collectionBulkWriteInsertModels, new BulkWriteOptions());
71+
}
72+
73+
[Benchmark]
74+
public void SmallDocClientBulkWriteInsertBenchmark()
75+
{
76+
_client.BulkWrite(_clientBulkWriteInsertModels, new ClientBulkWriteOptions());
6877
}
6978

7079
[GlobalCleanup]

0 commit comments

Comments
 (0)