Skip to content

Commit 4407104

Browse files
author
Haik
committed
update demo
1 parent 7407581 commit 4407104

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

test/PandaNuGet.Demo/Dtos/BulkBenchmarkResponse.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public enum BenchmarkMethod
99
{
1010
EFCore,
1111
Dapper,
12-
NpgsqlCopy
12+
NpgsqlCopy,
13+
ExternalBulkInsert
1314
}

test/PandaNuGet.Demo/PandaNuGet.Demo.csproj

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

1010
<ItemGroup>
1111
<PackageReference Include="Dapper" Version="2.1.35" />
12+
<PackageReference Include="EFCore.BulkExtensions.PostgreSql" Version="8.0.2" />
1213
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
1314
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1415
</ItemGroup>

test/PandaNuGet.Demo/Program.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
var results = new List<BulkBenchmarkResponse>
2525
{
2626
service.BulkInsertEfCore(minimumRows),
27-
service.BulkInsertNpgsqlCopy(minimumRows),
2827
service.BulkInsertDapper(minimumRows),
28+
service.BulkInsertNpgsqlCopy(minimumRows),
29+
service.BulkInsertExternal(minimumRows),
2930
service.BulkInsertEfCore(minimumRows * 10),
3031
service.BulkInsertDapper(minimumRows * 10),
3132
service.BulkInsertNpgsqlCopy(minimumRows * 10),
33+
service.BulkInsertExternal(minimumRows * 10),
3234
service.BulkInsertEfCore(minimumRows * 100),
3335
service.BulkInsertDapper(minimumRows * 100),
34-
service.BulkInsertNpgsqlCopy(minimumRows * 100)
36+
service.BulkInsertNpgsqlCopy(minimumRows * 100),
37+
service.BulkInsertExternal(minimumRows * 100)
3538
};
3639

3740
return results;
@@ -44,12 +47,15 @@
4447
await service.BulkInsertEfCoreAsync(minimumRows),
4548
await service.BulkInsertDapperAsync(minimumRows),
4649
await service.BulkInsertNpgsqlCopyAsync(minimumRows),
50+
await service.BulkInsertExternalAsync(minimumRows),
4751
await service.BulkInsertEfCoreAsync(minimumRows * 10),
4852
await service.BulkInsertDapperAsync(minimumRows * 10),
4953
await service.BulkInsertNpgsqlCopyAsync(minimumRows * 10),
54+
await service.BulkInsertExternalAsync(minimumRows * 10),
5055
await service.BulkInsertEfCoreAsync(minimumRows * 100),
5156
await service.BulkInsertDapperAsync(minimumRows * 100),
52-
await service.BulkInsertNpgsqlCopyAsync(minimumRows * 100)
57+
await service.BulkInsertNpgsqlCopyAsync(minimumRows * 100),
58+
await service.BulkInsertExternalAsync(minimumRows * 100)
5359
};
5460

5561
return results;

test/PandaNuGet.Demo/Services/BulkInsertService.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Text;
33
using Dapper;
4+
using EFCore.BulkExtensions;
45
using EFCore.PostgresExtensions.Extensions.BulkInsertExtension;
56
using Microsoft.EntityFrameworkCore;
67
using PandaNuGet.Demo.Context;
@@ -208,6 +209,42 @@ public async Task<BulkBenchmarkResponse> BulkInsertDapperAsync(int rowsCount, bo
208209
return new BulkBenchmarkResponse(BenchmarkMethod.Dapper, rowsCount, stopwatch.ElapsedMilliseconds.ToString());
209210
}
210211

212+
public async Task<BulkBenchmarkResponse> BulkInsertExternalAsync(int rowsCount, bool ignoreReset = false)
213+
{
214+
await ResetDbAsync(ignoreReset);
215+
var users = new List<UserEntity>();
216+
217+
for (int i = 0; i < rowsCount; i++)
218+
{
219+
users.Add(new UserEntity());
220+
}
221+
222+
var stopwatch = Stopwatch.StartNew();
223+
await dbContext.BulkInsertAsync(users);
224+
stopwatch.Stop();
225+
226+
return new BulkBenchmarkResponse(BenchmarkMethod.ExternalBulkInsert, rowsCount,
227+
stopwatch.ElapsedMilliseconds.ToString());
228+
}
229+
230+
public BulkBenchmarkResponse BulkInsertExternal(int rowsCount, bool ignoreReset = false)
231+
{
232+
ResetDb(ignoreReset);
233+
var users = new List<UserEntity>();
234+
235+
for (int i = 0; i < rowsCount; i++)
236+
{
237+
users.Add(new UserEntity());
238+
}
239+
240+
var stopwatch = Stopwatch.StartNew();
241+
dbContext.BulkInsert(users);
242+
stopwatch.Stop();
243+
244+
return new BulkBenchmarkResponse(BenchmarkMethod.ExternalBulkInsert, rowsCount,
245+
stopwatch.ElapsedMilliseconds.ToString());
246+
}
247+
211248
private async Task ResetDbAsync(bool ignore)
212249
{
213250
if (ignore)

test/PandaNuGet.Demo/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Error",
5-
"Microsoft.AspNetCore": "Error"
4+
"Default": "Debug",
5+
"Microsoft.AspNetCore": "Warning"
66
}
77
},
88
"AllowedHosts": "*",

0 commit comments

Comments
 (0)