-
-
Notifications
You must be signed in to change notification settings - Fork 74
Refactor benchmarks #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor benchmarks #1203
Changes from all commits
a131a11
9a42b18
8ac5cbe
f984b0b
e5e4075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ bin | |
obj | ||
out/ | ||
.idea | ||
/BenchmarkDotNet.Artifacts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
param( | ||
[ValidateSet('CommandBenchmark','LargeFetchBenchmark')] | ||
$Benchmark = 'CommandBenchmark' | ||
) | ||
|
||
$ErrorActionPreference = 'Stop' | ||
|
||
$projectFile = '.\src\FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj' | ||
|
||
# Run selected benchmark | ||
dotnet run ` | ||
--project $projectFile ` | ||
--configuration 'Release' ` | ||
-- ` | ||
--filter "*$($Benchmark)*" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* The contents of this file are subject to the Initial | ||
* Developer's Public License Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. | ||
* | ||
* Software distributed under the License is distributed on | ||
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either | ||
* express or implied. See the License for the specific | ||
* language governing rights and limitations under the License. | ||
* | ||
* All Rights Reserved. | ||
*/ | ||
|
||
//$Authors = Jiri Cincura (jiri@cincura.net) | ||
|
||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace FirebirdSql.Data.FirebirdClient.Benchmarks; | ||
|
||
public partial class CommandBenchmark | ||
{ | ||
[GlobalSetup(Target = nameof(Fetch))] | ||
public void FetchGlobalSetup() | ||
{ | ||
CreateDatabase(); | ||
|
||
using var conn = new FbConnection(ConnectionString); | ||
conn.Open(); | ||
|
||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
cmd.CommandText = $"CREATE TABLE foobar (x {DataType})"; | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
cmd.CommandText = $""" | ||
EXECUTE BLOCK AS | ||
DECLARE cnt INT; | ||
BEGIN | ||
cnt = {Count}; | ||
WHILE (cnt > 0) DO | ||
BEGIN | ||
INSERT INTO foobar VALUES (:cnt); | ||
cnt = cnt - 1; | ||
END | ||
END | ||
"""; | ||
cmd.ExecuteNonQuery(); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Fetch() | ||
{ | ||
using var conn = new FbConnection(ConnectionString); | ||
conn.Open(); | ||
|
||
using var cmd = conn.CreateCommand(); | ||
cmd.CommandText = "SELECT x FROM foobar"; | ||
|
||
using var reader = cmd.ExecuteReader(); | ||
while (reader.Read()) | ||
{ | ||
var _ = reader[0]; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,9 @@ | |
using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Toolchains.CsProj; | ||
using FirebirdSql.Data.FirebirdClient; | ||
using BenchmarkDotNet.Validators; | ||
|
||
namespace Perf; | ||
namespace FirebirdSql.Data.FirebirdClient.Benchmarks; | ||
|
||
[Config(typeof(Config))] | ||
public partial class CommandBenchmark | ||
|
@@ -34,30 +34,46 @@ public Config() | |
{ | ||
var baseJob = Job.Default | ||
.WithWarmupCount(3) | ||
.WithToolchain(CsProjCoreToolchain.NetCoreApp60) | ||
.WithPlatform(Platform.X64) | ||
.WithJit(Jit.RyuJit); | ||
|
||
AddJob( | ||
baseJob | ||
.WithToolchain(CsProjCoreToolchain.NetCoreApp80) | ||
.WithCustomBuildConfiguration("ReleaseNuGet") | ||
.WithId("NuGet80") | ||
.AsBaseline() | ||
); | ||
|
||
AddJob( | ||
baseJob | ||
.WithToolchain(CsProjCoreToolchain.NetCoreApp80) | ||
.WithCustomBuildConfiguration("Release") | ||
.WithId("Core80") | ||
); | ||
|
||
AddDiagnoser(MemoryDiagnoser.Default); | ||
AddJob(baseJob.WithCustomBuildConfiguration("Release").WithId("Project")); | ||
AddJob(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet").AsBaseline()); | ||
|
||
AddValidator(BaselineValidator.FailOnError); | ||
AddValidator(JitOptimizationsValidator.FailOnError); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If full JSON (*full.json) reports are exported then benchmarks results can be compared historically using ResultsComparer.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, I see how it is supposed to work now! |
||
} | ||
} | ||
|
||
protected const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey"; | ||
|
||
[Params("bigint", "varchar(10) character set utf8")] | ||
[Params("BIGINT", "VARCHAR(10) CHARACTER SET UTF8")] | ||
public string DataType { get; set; } | ||
|
||
[Params(100)] | ||
public int Count { get; set; } | ||
|
||
void GlobalSetupBase() | ||
static void CreateDatabase() | ||
{ | ||
FbConnection.CreateDatabase(ConnectionString, 16 * 1024, false, true); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
public static void GlobalCleanup() | ||
{ | ||
FbConnection.ClearAllPools(); | ||
FbConnection.DropDatabase(ConnectionString); | ||
|