Skip to content

Commit d4b4ec7

Browse files
committed
Updated Perf structure.
1 parent cbac305 commit d4b4ec7

File tree

5 files changed

+137
-40
lines changed

5 files changed

+137
-40
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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/blob/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+
using FirebirdSql.Data.FirebirdClient;
20+
21+
namespace Perf
22+
{
23+
partial class Benchmark
24+
{
25+
[GlobalSetup(Target = nameof(Execute))]
26+
public void ExecuteGlobalSetup()
27+
{
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+
}
38+
}
39+
40+
[Benchmark]
41+
public void Execute()
42+
{
43+
using (var conn = new FbConnection(ConnectionString))
44+
{
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 (int i = 0; i < 1000; i++)
52+
{
53+
p.Value = i;
54+
cmd.ExecuteNonQuery();
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}

Provider/src/Perf/FetchBenchmark.cs renamed to Provider/src/Perf/CommandBenchmark.Fetch.cs

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

1818
using BenchmarkDotNet.Attributes;
19-
using BenchmarkDotNet.Configs;
20-
using BenchmarkDotNet.Diagnosers;
21-
using BenchmarkDotNet.Environments;
22-
using BenchmarkDotNet.Jobs;
23-
using BenchmarkDotNet.Toolchains.CsProj;
2419
using FirebirdSql.Data.FirebirdClient;
2520

2621
namespace Perf
2722
{
28-
[Config(typeof(Config))]
29-
public class FetchBenchmark
23+
partial class Benchmark
3024
{
31-
class Config : ManualConfig
25+
[GlobalSetup(Target = nameof(Fetch))]
26+
public void FetchGlobalSetup()
3227
{
33-
public Config()
34-
{
35-
var baseJob = Job.Default
36-
.With(CsProjCoreToolchain.Current.Value)
37-
.With(Platform.X64)
38-
.With(Jit.RyuJit)
39-
.With(Runtime.Core);
40-
Add(MemoryDiagnoser.Default);
41-
Add(baseJob.WithCustomBuildConfiguration("Release").WithId("Project"));
42-
Add(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet"));
43-
}
44-
}
45-
46-
const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
47-
48-
[Params("int", "bigint", "varchar(10) character set utf8")]
49-
public string DataType { get; set; }
50-
51-
[GlobalSetup(Target = nameof(Fetch200k))]
52-
public void Fetch200kSetup()
53-
{
54-
FbConnection.CreateDatabase(ConnectionString, true);
28+
GlobalSetupBase();
5529
using (var conn = new FbConnection(ConnectionString))
5630
{
5731
conn.Open();
@@ -62,7 +36,7 @@ public void Fetch200kSetup()
6236
}
6337
using (var cmd = conn.CreateCommand())
6438
{
65-
cmd.CommandText = @"execute block as
39+
cmd.CommandText = $@"execute block as
6640
declare cnt int;
6741
begin
6842
cnt = 200000;
@@ -78,7 +52,7 @@ public void Fetch200kSetup()
7852
}
7953

8054
[Benchmark]
81-
public void Fetch200k()
55+
public void Fetch()
8256
{
8357
using (var conn = new FbConnection(ConnectionString))
8458
{
@@ -96,12 +70,5 @@ public void Fetch200k()
9670
}
9771
}
9872
}
99-
100-
[GlobalCleanup(Target = nameof(Fetch200k))]
101-
public void Fetch200kCleanup()
102-
{
103-
FbConnection.ClearAllPools();
104-
FbConnection.DropDatabase(ConnectionString);
105-
}
10673
}
10774
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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/blob/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+
using BenchmarkDotNet.Configs;
20+
using BenchmarkDotNet.Diagnosers;
21+
using BenchmarkDotNet.Environments;
22+
using BenchmarkDotNet.Jobs;
23+
using BenchmarkDotNet.Toolchains.CsProj;
24+
using FirebirdSql.Data.FirebirdClient;
25+
26+
namespace Perf
27+
{
28+
[Config(typeof(Config))]
29+
public partial class Benchmark
30+
{
31+
class Config : ManualConfig
32+
{
33+
public Config()
34+
{
35+
var baseJob = Job.ShortRun
36+
.With(CsProjCoreToolchain.Current.Value)
37+
.With(Platform.X64)
38+
.With(Jit.RyuJit)
39+
.With(Runtime.Core);
40+
Add(MemoryDiagnoser.Default);
41+
Add(baseJob.WithCustomBuildConfiguration("Release").WithId("Project"));
42+
Add(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet").AsBaseline());
43+
}
44+
}
45+
46+
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
47+
48+
[Params("bigint", "varchar(10) character set utf8")]
49+
public string DataType { get; set; }
50+
51+
void GlobalSetupBase()
52+
{
53+
FbConnection.CreateDatabase(ConnectionString, 16 * 1024, false, true);
54+
}
55+
56+
[GlobalCleanup]
57+
public void GlobalCleanup()
58+
{
59+
FbConnection.ClearAllPools();
60+
FbConnection.DropDatabase(ConnectionString);
61+
}
62+
}
63+
}

Provider/src/Perf/Perf.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
99
</ItemGroup>
1010

11+
<ItemGroup>
12+
<Compile Update="CommandBenchmark.*.cs">
13+
<DependentUpon>CommandBenchmark.cs</DependentUpon>
14+
</Compile>
15+
</ItemGroup>
16+
1117
<ItemGroup Condition="!$(Configuration.EndsWith('NuGet'))">
1218
<ProjectReference Include="..\FirebirdSql.Data.FirebirdClient\FirebirdSql.Data.FirebirdClient.csproj" />
1319
</ItemGroup>

Provider/src/Perf/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

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

18+
using System.Reflection;
1819
using BenchmarkDotNet.Running;
1920

2021
namespace Perf
@@ -23,7 +24,7 @@ class Program
2324
{
2425
static void Main(string[] args)
2526
{
26-
BenchmarkRunner.Run<FetchBenchmark>();
27+
BenchmarkRunner.Run(Assembly.GetExecutingAssembly());
2728
}
2829
}
2930
}

0 commit comments

Comments
 (0)