Skip to content

Commit 5852c9a

Browse files
committed
Extract BenchmarkBase with shared ConnectionString and env-var override
1 parent 8fa39ed commit 5852c9a

3 files changed

Lines changed: 44 additions & 26 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 System;
19+
using BenchmarkDotNet.Attributes;
20+
21+
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
22+
23+
public abstract class BenchmarkBase
24+
{
25+
const string DefaultConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
26+
27+
protected static readonly string ConnectionString =
28+
Environment.GetEnvironmentVariable("FIREBIRD_BENCHMARK_CS") ?? DefaultConnectionString;
29+
30+
protected static void CreateDatabase(int pageSize = 16 * 1024)
31+
{
32+
FbConnection.CreateDatabase(ConnectionString, pageSize, false, true);
33+
}
34+
35+
[GlobalCleanup]
36+
public void GlobalCleanup()
37+
{
38+
FbConnection.ClearAllPools();
39+
FbConnection.DropDatabase(ConnectionString);
40+
}
41+
}

src/FirebirdSql.Data.FirebirdClient.Benchmarks/CommandBenchmark.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@
2020
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
2121

2222
[Config(typeof(BenchmarkConfig))]
23-
public partial class CommandBenchmark
23+
public partial class CommandBenchmark : BenchmarkBase
2424
{
25-
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
26-
2725
[Params("BIGINT", "VARCHAR(10) CHARACTER SET UTF8")]
2826
public string DataType { get; set; }
2927

3028
[Params(100)]
3129
public int Count { get; set; }
32-
33-
static void CreateDatabase()
34-
{
35-
FbConnection.CreateDatabase(ConnectionString, 16 * 1024, false, true);
36-
}
37-
38-
[GlobalCleanup]
39-
public static void GlobalCleanup()
40-
{
41-
FbConnection.ClearAllPools();
42-
FbConnection.DropDatabase(ConnectionString);
43-
}
4430
}

src/FirebirdSql.Data.FirebirdClient.Benchmarks/LargeFetchBenchmark.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
44

55
[Config(typeof(BenchmarkConfig))]
6-
public class LargeFetchBenchmark
6+
public class LargeFetchBenchmark : BenchmarkBase
77
{
8-
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
9-
108
[Params(100_000)]
119
public int Count { get; set; }
1210

@@ -22,14 +20,7 @@ public class LargeFetchBenchmark
2220
[GlobalSetup(Target = nameof(Fetch))]
2321
public void FetchGlobalSetup()
2422
{
25-
FbConnection.CreateDatabase(ConnectionString, 8192, false, true);
26-
}
27-
28-
[GlobalCleanup]
29-
public void GlobalCleanup()
30-
{
31-
FbConnection.ClearAllPools();
32-
FbConnection.DropDatabase(ConnectionString);
23+
CreateDatabase(pageSize: 8192);
3324
}
3425

3526
[Benchmark]

0 commit comments

Comments
 (0)