Skip to content

Commit 3545ab9

Browse files
update nuget and prepare bench
1 parent 8266d44 commit 3545ab9

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed

Src/NpgsqlBenchmark/Benchmarks/CompareDapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NpgsqlBenchmark.Benchmarks
1212
[MemoryDiagnoser]
1313
[SimpleJob(RuntimeMoniker.Net70)]
1414
[HideColumns("Error", "StdDev", "Median", "RatioSD", "Gen0", "Gen1", "Gen2")]
15-
public class CompareDapper
15+
public partial class CompareDapper
1616
{
1717
[Params(10, 20, 30)]
1818
public int Size;
@@ -53,7 +53,7 @@ FROM person p
5353
LEFT JOIN identification i ON i.id = p.identification_id
5454
WHERE p.id > $1
5555
",
56-
"CompareRead",
56+
"GetAllPerson",
5757
typeof(Person)
5858
),
5959
Gedaq.Npgsql.Attributes.Parametr(parametrType: typeof(int), position: 1)
@@ -63,7 +63,7 @@ public void Npgsql()
6363
{
6464
for (int i = 0; i < Size; i++)
6565
{
66-
var persons = ((NpgsqlConnection)_connection).CompareRead(49999).ToList();
66+
var persons = GetAllPerson(_connection, 49999).ToList();
6767
}
6868
}
6969

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using Dapper;
4+
using Microsoft.Extensions.Configuration;
5+
using Npgsql;
6+
using NpgsqlBenchmark.Model;
7+
using System.IO;
8+
using System.Linq;
9+
10+
namespace NpgsqlBenchmark.Benchmarks
11+
{
12+
[MemoryDiagnoser]
13+
[SimpleJob(RuntimeMoniker.Net70)]
14+
[HideColumns("Error", "StdDev", "Median", "RatioSD", "Gen0", "Gen1", "Gen2")]
15+
public partial class ComparePrepareDapper
16+
{
17+
[Params(100, 200, 300)]
18+
public int Size;
19+
20+
private NpgsqlConnection _connection;
21+
22+
[GlobalSetup]
23+
public void Setup()
24+
{
25+
var root = new ConfigurationBuilder()
26+
.SetBasePath(Directory.GetCurrentDirectory())
27+
.AddJsonFile("settings.json", optional: false)
28+
.Build()
29+
;
30+
31+
_connection = new NpgsqlConnection(root.GetConnectionString("SqlConnection"));
32+
_connection.Open();
33+
}
34+
35+
[GlobalCleanup]
36+
public void Cleanup()
37+
{
38+
_connection?.Dispose();
39+
}
40+
41+
[Gedaq.Npgsql.Attributes.Query(
42+
@"
43+
SELECT
44+
p.id,
45+
p.firstname,
46+
~StartInner::Identification:id~
47+
i.id,
48+
i.typename,
49+
~EndInner::Identification~
50+
p.middlename,
51+
p.lastname
52+
FROM person p
53+
LEFT JOIN identification i ON i.id = p.identification_id
54+
WHERE p.id < $1
55+
",
56+
"GetAllPerson",
57+
typeof(Person)
58+
),
59+
Gedaq.Npgsql.Attributes.Parametr(parametrType: typeof(int), position: 1)
60+
]
61+
[Benchmark(Description = $"Gedaq.Npgsql")]
62+
public void Npgsql()
63+
{
64+
using var getAllCmd = CreateGetAllPersonCommand(_connection, prepare: true);
65+
for (int i = 0; i < Size; i++)
66+
{
67+
SetGetAllPersonParametrs(getAllCmd, i);
68+
var persons = ExecuteGetAllPersonCommand(getAllCmd).ToList();
69+
}
70+
}
71+
72+
public class Parametr
73+
{
74+
public int id { get; set; }
75+
}
76+
77+
[Benchmark(Baseline = true, Description = "Dapper")]
78+
public void Dapper()
79+
{
80+
var param = new Parametr();
81+
for (int i = 0; i < Size; i++)
82+
{
83+
param.id = i;
84+
var persons = _connection.Query<Person, Identification, Person>(@"
85+
SELECT
86+
p.id,
87+
p.firstname,
88+
p.middlename,
89+
p.lastname,
90+
p.identification_id,
91+
i.typename
92+
FROM person p
93+
LEFT JOIN identification i ON i.id = p.identification_id
94+
WHERE p.id < @id
95+
",
96+
(person, ident) =>
97+
{
98+
person.Identification = ident;
99+
return person;
100+
},
101+
param,
102+
splitOn: "identification_id"
103+
)
104+
.ToList();
105+
}
106+
}
107+
}
108+
}

Src/NpgsqlBenchmark/NpgsqlBenchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
88
<PackageReference Include="Dapper" Version="2.0.123" />
9-
<PackageReference Include="Gedaq" Version="1.4.6.7" />
9+
<PackageReference Include="Gedaq" Version="1.4.6.8" />
1010
<PackageReference Include="Gedaq.DbConnection" Version="1.2.3" />
1111
<PackageReference Include="Gedaq.Npgsql" Version="1.2.3" />
1212
<PackageReference Include="System.Linq.Async" Version="6.0.1" />

Src/NpgsqlBenchmark/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ internal class Program
1212
static void Main(string[] args)
1313
{
1414
//FillTestDatabase();
15-
BenchmarkRunner.Run<CompareDapper>();
15+
BenchmarkRunner.Run<ComparePrepareDapper>();
16+
//BenchmarkRunner.Run<CompareDapper>();
1617
//BenchmarkRunner.Run<QueryMap>();
1718
//BenchmarkRunner.Run<BinaryImportMap>();
1819
}

0 commit comments

Comments
 (0)