forked from cincuranet/FirebirdSql.Data.FirebirdClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformanceBenchmark.cs
More file actions
109 lines (96 loc) · 2.74 KB
/
Copy pathPerformanceBenchmark.cs
File metadata and controls
109 lines (96 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Diagnostics.Tracing;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Toolchains.CsProj;
using FirebirdSql.Data.FirebirdClient;
using Microsoft.Diagnostics.Tracing.Parsers;
namespace Perf;
[Config(typeof(Config))]
public class PerformanceBenchmark
{
class Config : ManualConfig
{
private const ClrTraceEventParser.Keywords EventParserKeywords =
ClrTraceEventParser.Keywords.Exception
| ClrTraceEventParser.Keywords.GC
| ClrTraceEventParser.Keywords.Jit
| ClrTraceEventParser.Keywords.JitTracing // for the inlining events
| ClrTraceEventParser.Keywords.Loader
| ClrTraceEventParser.Keywords.NGen;
public Config()
{
var baseJob = Job.ShortRun
.WithWarmupCount(3)
.WithToolchain(CsProjCoreToolchain.NetCoreApp80)
.WithPlatform(Platform.X64)
.WithJit(Jit.RyuJit);
AddDiagnoser(MemoryDiagnoser.Default);
AddDiagnoser(new EventPipeProfiler(providers: [
new(
ClrTraceEventParser.ProviderName,
EventLevel.Verbose,
(long)EventParserKeywords
)
]));
AddJob(baseJob.WithCustomBuildConfiguration("Release").WithId("Project"));
AddJob(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet").AsBaseline());
}
}
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";
[Params(10_000)]
public int Count { get; set; }
[Params(
"BIGINT",
"CHAR(255) CHARACTER SET UTF8",
"CHAR(255) CHARACTER SET OCTETS",
"BLOB SUB_TYPE TEXT CHARACTER SET UTF8",
"BLOB SUB_TYPE BINARY"
)]
public string DataType { get; set; }
[GlobalSetup(Target = nameof(Fetch))]
public void FetchGlobalSetup()
{
FbConnection.CreateDatabase(ConnectionString, 8192, false, true);
}
[GlobalCleanup]
public void GlobalCleanup()
{
FbConnection.ClearAllPools();
FbConnection.DropDatabase(ConnectionString);
}
[Benchmark]
public void Fetch()
{
using var conn = new FbConnection(ConnectionString);
conn.Open();
using var cmd = conn.CreateCommand();
cmd.CommandText = $@"
EXECUTE BLOCK RETURNS (result {DataType}) AS
DECLARE cnt INTEGER;
BEGIN
SELECT {GetFillExpression(DataType)} FROM rdb$database INTO result;
cnt = {Count};
WHILE (cnt > 0) DO
BEGIN
SUSPEND;
cnt = cnt - 1;
END
END
";
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
_ = reader[0];
}
}
private static string GetFillExpression(string dataType) =>
dataType switch
{
{ } when dataType.StartsWith("BLOB") => $"LPAD('', 1023, '{dataType};')",
{ } when dataType.StartsWith("CHAR") => $"LPAD('', 255, '{dataType};')",
_ => "9223372036854775807" /* BIGINT */
};
}