Skip to content

Commit e228b2b

Browse files
Add a performance check of the generic batcher.
1 parent 11b45e7 commit e228b2b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/NHibernate.Test/Ado/GenericBatchingBatcherFixture.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.Diagnostics;
34
using System.Linq;
45
using NHibernate.AdoNet;
56
using NHibernate.Cfg;
@@ -61,6 +62,41 @@ public void BatchSizeTest()
6162
Cleanup();
6263
}
6364

65+
// Demonstrates a 50% performance gain with SQL-Server, around 40% for PostgreSQL,
66+
// around 15% for MySql, but around 200% performance loss for SQLite.
67+
// (Tested with databases on same machine for all cases.)
68+
[Theory, Explicit("This is a performance test, to be checked manually.")]
69+
public void MassivePerformanceTest(bool batched)
70+
{
71+
if (batched)
72+
{
73+
// Bring down batch size to a reasonnable value, otherwise performances are worsen.
74+
cfg.SetProperty(Environment.BatchSize, "50");
75+
}
76+
else
77+
{
78+
cfg.SetProperty(Environment.BatchStrategy, typeof(NonBatchingBatcherFactory).AssemblyQualifiedName);
79+
cfg.Properties.Remove(Environment.BatchSize);
80+
}
81+
RebuildSessionFactory();
82+
83+
try
84+
{
85+
// Warm up
86+
MassiveInsertUpdateDeleteTest();
87+
88+
var chrono = new Stopwatch();
89+
chrono.Start();
90+
MassiveInsertUpdateDeleteTest();
91+
Console.WriteLine($"Elapsed time: {chrono.Elapsed}");
92+
}
93+
finally
94+
{
95+
Configure(cfg);
96+
RebuildSessionFactory();
97+
}
98+
}
99+
64100
private void BatchInsert(int totalRecords)
65101
{
66102
Sfi.Statistics.Clear();

src/NHibernate.Test/Async/Ado/GenericBatchingBatcherFixture.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using System;
1212
using System.Collections;
13+
using System.Diagnostics;
1314
using System.Linq;
1415
using NHibernate.AdoNet;
1516
using NHibernate.Cfg;
@@ -74,6 +75,41 @@ public async Task BatchSizeTestAsync()
7475
await (CleanupAsync());
7576
}
7677

78+
// Demonstrates a 50% performance gain with SQL-Server, around 40% for PostgreSQL,
79+
// around 15% for MySql, but around 200% performance loss for SQLite.
80+
// (Tested with databases on same machine for all cases.)
81+
[Theory, Explicit("This is a performance test, to be checked manually.")]
82+
public async Task MassivePerformanceTestAsync(bool batched)
83+
{
84+
if (batched)
85+
{
86+
// Bring down batch size to a reasonnable value, otherwise performances are worsen.
87+
cfg.SetProperty(Environment.BatchSize, "50");
88+
}
89+
else
90+
{
91+
cfg.SetProperty(Environment.BatchStrategy, typeof(NonBatchingBatcherFactory).AssemblyQualifiedName);
92+
cfg.Properties.Remove(Environment.BatchSize);
93+
}
94+
RebuildSessionFactory();
95+
96+
try
97+
{
98+
// Warm up
99+
await (MassiveInsertUpdateDeleteTestAsync());
100+
101+
var chrono = new Stopwatch();
102+
chrono.Start();
103+
await (MassiveInsertUpdateDeleteTestAsync());
104+
Console.WriteLine($"Elapsed time: {chrono.Elapsed}");
105+
}
106+
finally
107+
{
108+
Configure(cfg);
109+
RebuildSessionFactory();
110+
}
111+
}
112+
77113
private async Task BatchInsertAsync(int totalRecords, CancellationToken cancellationToken = default(CancellationToken))
78114
{
79115
Sfi.Statistics.Clear();

0 commit comments

Comments
 (0)