Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd2e3a0

Browse files
committed
Refactor: Benchmarks.
- Rename project 'Perf' to 'FirebirdSql.Data.FirebirdClient.Benchmarks'. - Update project to use .net8. - Upgrade BenchmarkDotNet to version 0.14.0. - Update baseline nuget package to v10.3.1. - Add /BenchmarkDotNet.Artifacts to .gitignore. - Pass command-line arguments to BenchmarkDotNet engine. - Apply SQL Formatting. Use raw strings. - Add script run-benchmark.ps1.
1 parent 47a5b9b commit bd2e3a0

File tree

9 files changed

+145
-126
lines changed

9 files changed

+145
-126
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ bin
66
obj
77
out/
88
.idea
9+
/BenchmarkDotNet.Artifacts

‎run-benchmark.ps1‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
param(
2+
[ValidateSet('CommandBenchmark')]
3+
$Benchmark = 'CommandBenchmark'
4+
)
5+
6+
$ErrorActionPreference = 'Stop'
7+
8+
$projectFile = '.\src\FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj'
9+
10+
# Run selected benchmark
11+
dotnet run `
12+
--project $projectFile `
13+
--configuration 'Release' `
14+
-- `
15+
--filter "*$($Benchmark)*"

‎src/Perf/CommandBenchmark.Execute.cs‎ renamed to ‎src/FirebirdSql.Data.FirebirdClient.Benchmarks/CommandBenchmark.Execute.cs‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,40 @@
1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

1818
using BenchmarkDotNet.Attributes;
19-
using FirebirdSql.Data.FirebirdClient;
2019

21-
namespace Perf;
20+
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
2221

23-
partial class CommandBenchmark
22+
publicpartial class CommandBenchmark
2423
{
2524
[GlobalSetup(Target = nameof(Execute))]
2625
public void ExecuteGlobalSetup()
2726
{
28-
GlobalSetupBase();
29-
using (var conn = new FbConnection(ConnectionString))
30-
{
31-
conn.Open();
32-
using (var cmd = conn.CreateCommand())
33-
{
34-
cmd.CommandText = $"create table foobar (x {DataType})";
35-
cmd.ExecuteNonQuery();
36-
}
37-
}
27+
CreateDatabase();
28+
29+
using var conn = new FbConnection(ConnectionString);
30+
conn.Open();
31+
32+
using var cmd = conn.CreateCommand();
33+
cmd.CommandText = $"CREATE TABLE foobar (x {DataType})";
34+
cmd.ExecuteNonQuery();
3835
}
3936

4037
[Benchmark]
4138
public void Execute()
4239
{
43-
using (var conn = new FbConnection(ConnectionString))
40+
using var conn = new FbConnection(ConnectionString);
41+
conn.Open();
42+
43+
using var cmd = conn.CreateCommand();
44+
cmd.CommandText = @"INSERT INTO foobar (x) VALUES (@cnt)";
45+
46+
var p = new FbParameter() { ParameterName = "@cnt" };
47+
cmd.Parameters.Add(p);
48+
49+
for (var i = 0; i < Count; i++)
4450
{
45-
conn.Open();
46-
using (var cmd = conn.CreateCommand())
47-
{
48-
cmd.CommandText = @"insert into foobar values (@cnt)";
49-
var p = new FbParameter() { ParameterName = "@cnt" };
50-
cmd.Parameters.Add(p);
51-
for (var i = 0; i < Count; i++)
52-
{
53-
p.Value = i;
54-
cmd.ExecuteNonQuery();
55-
}
56-
}
51+
p.Value = i;
52+
cmd.ExecuteNonQuery();
5753
}
5854
}
5955
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* The contents of this file are subject to the Initial
3+
* Developer's Public License Version 1.0 (the "License");
4+
* you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
7+
*
8+
* Software distributed under the License is distributed on
9+
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10+
* express or implied. See the License for the specific
11+
* language governing rights and limitations under the License.
12+
*
13+
* All Rights Reserved.
14+
*/
15+
16+
//$Authors = Jiri Cincura (jiri@cincura.net)
17+
18+
using BenchmarkDotNet.Attributes;
19+
20+
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
21+
22+
public partial class CommandBenchmark
23+
{
24+
[GlobalSetup(Target = nameof(Fetch))]
25+
public void FetchGlobalSetup()
26+
{
27+
CreateDatabase();
28+
29+
using var conn = new FbConnection(ConnectionString);
30+
conn.Open();
31+
32+
using (var cmd = conn.CreateCommand())
33+
{
34+
cmd.CommandText = $"CREATE TABLE foobar (x {DataType})";
35+
cmd.ExecuteNonQuery();
36+
}
37+
38+
using (var cmd = conn.CreateCommand())
39+
{
40+
cmd.CommandText = $"""
41+
EXECUTE BLOCK AS
42+
DECLARE cnt INT;
43+
BEGIN
44+
cnt = {Count};
45+
WHILE (cnt > 0) DO
46+
BEGIN
47+
INSERT INTO foobar VALUES (:cnt);
48+
cnt = cnt - 1;
49+
END
50+
END
51+
""";
52+
cmd.ExecuteNonQuery();
53+
}
54+
}
55+
56+
[Benchmark]
57+
public void Fetch()
58+
{
59+
using var conn = new FbConnection(ConnectionString);
60+
conn.Open();
61+
62+
using var cmd = conn.CreateCommand();
63+
cmd.CommandText = "SELECT x FROM foobar";
64+
65+
using var reader = cmd.ExecuteReader();
66+
while (reader.Read())
67+
{
68+
var _ = reader[0];
69+
}
70+
}
71+
}

‎src/Perf/CommandBenchmark.cs‎ renamed to ‎src/FirebirdSql.Data.FirebirdClient.Benchmarks/CommandBenchmark.cs‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
using BenchmarkDotNet.Environments;
2222
using BenchmarkDotNet.Jobs;
2323
using BenchmarkDotNet.Toolchains.CsProj;
24-
using FirebirdSql.Data.FirebirdClient;
24+
using BenchmarkDotNet.Validators;
2525

26-
namespace Perf;
26+
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
2727

2828
[Config(typeof(Config))]
2929
public partial class CommandBenchmark
@@ -34,30 +34,46 @@ public Config()
3434
{
3535
var baseJob = Job.Default
3636
.WithWarmupCount(3)
37-
.WithToolchain(CsProjCoreToolchain.NetCoreApp60)
3837
.WithPlatform(Platform.X64)
3938
.WithJit(Jit.RyuJit);
39+
40+
AddJob(
41+
baseJob
42+
.WithToolchain(CsProjCoreToolchain.NetCoreApp80)
43+
.WithCustomBuildConfiguration("ReleaseNuGet")
44+
.WithId("NuGet80")
45+
.AsBaseline()
46+
);
47+
48+
AddJob(
49+
baseJob
50+
.WithToolchain(CsProjCoreToolchain.NetCoreApp80)
51+
.WithCustomBuildConfiguration("Release")
52+
.WithId("Core80")
53+
);
54+
4055
AddDiagnoser(MemoryDiagnoser.Default);
41-
AddJob(baseJob.WithCustomBuildConfiguration("Release").WithId("Project"));
42-
AddJob(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet").AsBaseline());
56+
57+
AddValidator(BaselineValidator.FailOnError);
58+
AddValidator(JitOptimizationsValidator.FailOnError);
4359
}
4460
}
4561

4662
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
4763

48-
[Params("bigint", "varchar(10) character set utf8")]
64+
[Params("BIGINT", "VARCHAR(10) CHARACTER SET UTF8")]
4965
public string DataType { get; set; }
5066

5167
[Params(100)]
5268
public int Count { get; set; }
5369

54-
void GlobalSetupBase()
70+
staticvoid CreateDatabase()
5571
{
5672
FbConnection.CreateDatabase(ConnectionString, 16 * 1024, false, true);
5773
}
5874

5975
[GlobalCleanup]
60-
public void GlobalCleanup()
76+
public staticvoid GlobalCleanup()
6177
{
6278
FbConnection.ClearAllPools();
6379
FbConnection.DropDatabase(ConnectionString);

‎src/Perf/Perf.csproj‎ renamed to ‎src/FirebirdSql.Data.FirebirdClient.Benchmarks/FirebirdSql.Data.FirebirdClient.Benchmarks.csproj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SkipSourceLink>true</SkipSourceLink>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
8+
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
99
</ItemGroup>
1010

1111
<ItemGroup>
@@ -19,6 +19,6 @@
1919
</ItemGroup>
2020

2121
<ItemGroup Condition="$(Configuration.EndsWith('NuGet'))">
22-
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="8.5.4" />
22+
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="10.3.1" />
2323
</ItemGroup>
2424
</Project>

‎src/Perf/Program.cs‎ renamed to ‎src/FirebirdSql.Data.FirebirdClient.Benchmarks/Program.cs‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@
1515

1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

18-
using System.Reflection;
1918
using BenchmarkDotNet.Running;
2019

21-
namespace Perf;
22-
23-
class Program
24-
{
25-
static void Main(string[] args)
26-
{
27-
BenchmarkRunner.Run(Assembly.GetExecutingAssembly());
28-
}
29-
}
20+
BenchmarkSwitcher
21+
.FromAssembly(typeof(Program).Assembly)
22+
.Run(args);

‎src/NETProvider.sln‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FirebirdSql.EntityFramework
3434
EndProject
3535
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "FirebirdSql.Data.External", "FirebirdSql.Data.External\FirebirdSql.Data.External.shproj", "{884EE120-B22E-4940-8C1C-626F13028376}"
3636
EndProject
37-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Perf", "Perf\Perf.csproj", "{BB846245-545A-4506-A0DA-0041C535D3A9}"
37+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{CE2BB2BB-4639-49EA-8369-0215A1D7245D}"
3838
EndProject
39-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Perf", "Perf", "{CE2BB2BB-4639-49EA-8369-0215A1D7245D}"
39+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FirebirdSql.Data.FirebirdClient.Benchmarks", "FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj", "{77A3DB18-75E9-451D-B434-6A95F9015FF7}"
4040
EndProject
4141
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scratchpad", "Scratchpad", "{5F1D1BB9-4657-424C-B3DE-75818824940E}"
4242
EndProject
@@ -76,14 +76,14 @@ Global
7676
{2925DB97-5B39-4D9E-90CC-F7470F9AA8F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
7777
{2925DB97-5B39-4D9E-90CC-F7470F9AA8F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
7878
{2925DB97-5B39-4D9E-90CC-F7470F9AA8F3}.Release|Any CPU.Build.0 = Release|Any CPU
79-
{BB846245-545A-4506-A0DA-0041C535D3A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
80-
{BB846245-545A-4506-A0DA-0041C535D3A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
81-
{BB846245-545A-4506-A0DA-0041C535D3A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
82-
{BB846245-545A-4506-A0DA-0041C535D3A9}.Release|Any CPU.Build.0 = Release|Any CPU
8379
{C3F47B3D-FA1F-4665-A58D-63B6FFDCD65F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8480
{C3F47B3D-FA1F-4665-A58D-63B6FFDCD65F}.Debug|Any CPU.Build.0 = Debug|Any CPU
8581
{C3F47B3D-FA1F-4665-A58D-63B6FFDCD65F}.Release|Any CPU.ActiveCfg = Release|Any CPU
8682
{C3F47B3D-FA1F-4665-A58D-63B6FFDCD65F}.Release|Any CPU.Build.0 = Release|Any CPU
83+
{77A3DB18-75E9-451D-B434-6A95F9015FF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
84+
{77A3DB18-75E9-451D-B434-6A95F9015FF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
85+
{77A3DB18-75E9-451D-B434-6A95F9015FF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
86+
{77A3DB18-75E9-451D-B434-6A95F9015FF7}.Release|Any CPU.Build.0 = Release|Any CPU
8787
EndGlobalSection
8888
GlobalSection(SolutionProperties) = preSolution
8989
HideSolutionNode = FALSE
@@ -98,10 +98,10 @@ Global
9898
{42A00B25-673E-449A-9B89-BE89344F96F0} = {AD392B88-6637-4744-BDF9-8FB9453C9042}
9999
{2925DB97-5B39-4D9E-90CC-F7470F9AA8F3} = {AD392B88-6637-4744-BDF9-8FB9453C9042}
100100
{884EE120-B22E-4940-8C1C-626F13028376} = {C94B5B06-9023-43C1-9B0D-6BDD504F9A06}
101-
{BB846245-545A-4506-A0DA-0041C535D3A9} = {CE2BB2BB-4639-49EA-8369-0215A1D7245D}
102101
{CE2BB2BB-4639-49EA-8369-0215A1D7245D} = {C94B5B06-9023-43C1-9B0D-6BDD504F9A06}
103102
{5F1D1BB9-4657-424C-B3DE-75818824940E} = {C94B5B06-9023-43C1-9B0D-6BDD504F9A06}
104103
{C3F47B3D-FA1F-4665-A58D-63B6FFDCD65F} = {5F1D1BB9-4657-424C-B3DE-75818824940E}
104+
{77A3DB18-75E9-451D-B434-6A95F9015FF7} = {CE2BB2BB-4639-49EA-8369-0215A1D7245D}
105105
EndGlobalSection
106106
GlobalSection(ExtensibilityGlobals) = postSolution
107107
SolutionGuid = {D574B071-15C1-4024-BB37-78D690F61070}

‎src/Perf/CommandBenchmark.Fetch.cs‎

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /