Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bin
obj
out/
.idea
/BenchmarkDotNet.Artifacts
13 changes: 13 additions & 0 deletions run-benchmark.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param(
[Parameter(Mandatory=$True)]
[ValidateSet('CommandBenchmark','PerformanceBenchmark')]
$Benchmark = 'CommandBenchmark'
)

$ErrorActionPreference = 'Stop'

# Make a release build
dotnet build .\src\Perf\Perf.csproj --configuration 'Release'

# Run selected benchmark
& .\src\Perf\bin\Release\net8.0\Perf.exe --filter "*$($Benchmark)*"
2 changes: 1 addition & 1 deletion src/Perf/CommandBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Config()
{
var baseJob = Job.Default
.WithWarmupCount(3)
.WithToolchain(CsProjCoreToolchain.NetCoreApp60)
.WithToolchain(CsProjCoreToolchain.NetCoreApp80)
.WithPlatform(Platform.X64)
.WithJit(Jit.RyuJit);
AddDiagnoser(MemoryDiagnoser.Default);
Expand Down
4 changes: 2 additions & 2 deletions src/Perf/Perf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SkipSourceLink>true</SkipSourceLink>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -19,6 +19,6 @@
</ItemGroup>

<ItemGroup Condition="$(Configuration.EndsWith('NuGet'))">
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="8.5.4" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="10.3.1" />
</ItemGroup>
</Project>
109 changes: 109 additions & 0 deletions src/Perf/PerformanceBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 */
};
}
5 changes: 3 additions & 2 deletions src/Perf/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

using System.Reflection;
using BenchmarkDotNet.Running;

namespace Perf;
Expand All @@ -24,6 +23,8 @@ class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run(Assembly.GetExecutingAssembly());
BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
.Run(args);
}
}