File tree Expand file tree Collapse file tree
src/FirebirdSql.Data.FirebirdClient.Benchmarks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515
1616//$Authors = Jiri Cincura (jiri@cincura.net)
1717
18+ using System . Threading . Tasks ;
1819using BenchmarkDotNet . Attributes ;
1920
2021namespace FirebirdSql . Data . FirebirdClient . Benchmarks ;
2122
2223public partial class CommandBenchmark
2324{
24- [ GlobalSetup ( Target = nameof ( Execute ) ) ]
25+ [ GlobalSetup ( Targets = new [ ] { nameof ( Execute ) , nameof ( ExecuteAsync ) } ) ]
2526 public void ExecuteGlobalSetup ( )
2627 {
2728 CreateDatabase ( ) ;
@@ -52,4 +53,23 @@ public void Execute()
5253 cmd . ExecuteNonQuery ( ) ;
5354 }
5455 }
56+
57+ [ Benchmark ]
58+ public async Task ExecuteAsync ( )
59+ {
60+ await using var conn = new FbConnection ( ConnectionString ) ;
61+ await conn . OpenAsync ( ) ;
62+
63+ await using var cmd = conn . CreateCommand ( ) ;
64+ cmd . CommandText = @"INSERT INTO foobar (x) VALUES (@cnt)" ;
65+
66+ var p = new FbParameter ( ) { ParameterName = "@cnt" } ;
67+ cmd . Parameters . Add ( p ) ;
68+
69+ for ( var i = 0 ; i < Count ; i ++ )
70+ {
71+ p . Value = i ;
72+ await cmd . ExecuteNonQueryAsync ( ) ;
73+ }
74+ }
5575}
Original file line number Diff line number Diff line change 1515
1616//$Authors = Jiri Cincura (jiri@cincura.net)
1717
18+ using System . Threading . Tasks ;
1819using BenchmarkDotNet . Attributes ;
1920
2021namespace FirebirdSql . Data . FirebirdClient . Benchmarks ;
2122
2223public partial class CommandBenchmark
2324{
24- [ GlobalSetup ( Target = nameof ( Fetch ) ) ]
25+ [ GlobalSetup ( Targets = new [ ] { nameof ( Fetch ) , nameof ( FetchAsync ) } ) ]
2526 public void FetchGlobalSetup ( )
2627 {
2728 CreateDatabase ( ) ;
@@ -70,4 +71,24 @@ public object Fetch()
7071 }
7172 return last ;
7273 }
74+
75+ [ Benchmark ]
76+ public async Task < object > FetchAsync ( )
77+ {
78+ await using var conn = new FbConnection ( ConnectionString ) ;
79+ await conn . OpenAsync ( ) ;
80+
81+ await using var cmd = conn . CreateCommand ( ) ;
82+ cmd . CommandText = "SELECT x FROM foobar" ;
83+
84+ object last = null ;
85+ await using var reader = await cmd . ExecuteReaderAsync ( ) ;
86+ while ( await reader . ReadAsync ( ) )
87+ {
88+ last = reader [ 0 ] ;
89+ }
90+ return last ;
91+ }
92+ }
93+ }
7394}
You can’t perform that action at this time.
0 commit comments