Skip to content

Commit 3c3ce6e

Browse files
committed
Add async benchmark variants for Execute and Fetch
1 parent 32c46bb commit 3c3ce6e

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

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

18+
using System.Threading.Tasks;
1819
using BenchmarkDotNet.Attributes;
1920

2021
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
2122

2223
public 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
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

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

18+
using System.Threading.Tasks;
1819
using BenchmarkDotNet.Attributes;
1920

2021
namespace FirebirdSql.Data.FirebirdClient.Benchmarks;
2122

2223
public 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
}

0 commit comments

Comments
 (0)