1+ using BenchmarkDotNet . Attributes ;
2+ using BenchmarkDotNet . Configs ;
3+ using BenchmarkDotNet . Diagnosers ;
4+ using BenchmarkDotNet . Environments ;
5+ using BenchmarkDotNet . Jobs ;
6+ using BenchmarkDotNet . Toolchains . CsProj ;
7+ using BenchmarkDotNet . Validators ;
8+
9+ namespace FirebirdSql . Data . FirebirdClient . Benchmarks ;
10+
11+ [ Config ( typeof ( Config ) ) ]
12+ public class LargeFetchBenchmark
13+ {
14+ class Config : ManualConfig
15+ {
16+ public Config ( )
17+ {
18+ var baseJob = Job . Default
19+ . WithWarmupCount ( 3 )
20+ . WithPlatform ( Platform . X64 )
21+ . WithJit ( Jit . RyuJit ) ;
22+
23+ AddJob (
24+ baseJob
25+ . WithToolchain ( CsProjCoreToolchain . NetCoreApp80 )
26+ . WithCustomBuildConfiguration ( "ReleaseNuGet" )
27+ . WithId ( "NuGet80" )
28+ . AsBaseline ( )
29+ ) ;
30+
31+ AddJob (
32+ baseJob
33+ . WithToolchain ( CsProjCoreToolchain . NetCoreApp80 )
34+ . WithCustomBuildConfiguration ( "Release" )
35+ . WithId ( "Core80" )
36+ ) ;
37+
38+ AddDiagnoser ( MemoryDiagnoser . Default ) ;
39+
40+ AddValidator ( BaselineValidator . FailOnError ) ;
41+ AddValidator ( JitOptimizationsValidator . FailOnError ) ;
42+ }
43+ }
44+
45+ protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey" ;
46+
47+ [ Params ( 100_000 ) ]
48+ public int Count { get ; set ; }
49+
50+ [ Params (
51+ "BIGINT" ,
52+ "CHAR(255) CHARACTER SET UTF8" ,
53+ "CHAR(255) CHARACTER SET OCTETS" ,
54+ "BLOB SUB_TYPE TEXT CHARACTER SET UTF8" ,
55+ "BLOB SUB_TYPE BINARY"
56+ ) ]
57+ public string DataType { get ; set ; }
58+
59+ [ GlobalSetup ( Target = nameof ( Fetch ) ) ]
60+ public void FetchGlobalSetup ( )
61+ {
62+ FbConnection . CreateDatabase ( ConnectionString , 8192 , false , true ) ;
63+ }
64+
65+ [ GlobalCleanup ]
66+ public void GlobalCleanup ( )
67+ {
68+ FbConnection . ClearAllPools ( ) ;
69+ FbConnection . DropDatabase ( ConnectionString ) ;
70+ }
71+
72+ [ Benchmark ]
73+ public void Fetch ( )
74+ {
75+ using var conn = new FbConnection ( ConnectionString ) ;
76+ conn . Open ( ) ;
77+
78+ using var cmd = conn . CreateCommand ( ) ;
79+ cmd . CommandText = $@ "
80+ EXECUTE BLOCK RETURNS (result { DataType } ) AS
81+ DECLARE cnt INTEGER;
82+ BEGIN
83+ SELECT { GetFillExpression ( DataType ) } FROM rdb$database INTO result;
84+ cnt = { Count } ;
85+ WHILE (cnt > 0) DO
86+ BEGIN
87+ SUSPEND;
88+ cnt = cnt - 1;
89+ END
90+ END
91+ " ;
92+
93+ using var reader = cmd . ExecuteReader ( ) ;
94+ while ( reader . Read ( ) )
95+ {
96+ _ = reader [ 0 ] ;
97+ }
98+ }
99+ private static string GetFillExpression ( string dataType ) =>
100+ dataType switch
101+ {
102+ { } when dataType . StartsWith ( "BLOB" ) => $ "LPAD('', 1023, '{ dataType } ;')",
103+ { } when dataType . StartsWith ( "CHAR" ) => $ "LPAD('', 255, '{ dataType } ;')",
104+ _ => "9223372036854775807" /* BIGINT */
105+ } ;
106+ }
0 commit comments