|
| 1 | +/* |
| 2 | + * The contents of this file are subject to the Initial |
| 3 | + * Developer's Public License Version 1.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the |
| 5 | + * License. You may obtain a copy of the License at |
| 6 | + * https://github.com/FirebirdSQL/NETProvider/blob/master/license.txt. |
| 7 | + * |
| 8 | + * Software distributed under the License is distributed on |
| 9 | + * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either |
| 10 | + * express or implied. See the License for the specific |
| 11 | + * language governing rights and limitations under the License. |
| 12 | + * |
| 13 | + * All Rights Reserved. |
| 14 | + */ |
| 15 | + |
| 16 | +//$Authors = Jiri Cincura (jiri@cincura.net) |
| 17 | + |
| 18 | +using BenchmarkDotNet.Attributes; |
| 19 | +using BenchmarkDotNet.Configs; |
| 20 | +using BenchmarkDotNet.Diagnosers; |
| 21 | +using BenchmarkDotNet.Environments; |
| 22 | +using BenchmarkDotNet.Jobs; |
| 23 | +using BenchmarkDotNet.Toolchains.CsProj; |
| 24 | +using FirebirdSql.Data.FirebirdClient; |
| 25 | + |
| 26 | +namespace Perf |
| 27 | +{ |
| 28 | + [Config(typeof(Config))] |
| 29 | + public class FetchBenchmark |
| 30 | + { |
| 31 | + class Config : ManualConfig |
| 32 | + { |
| 33 | + public Config() |
| 34 | + { |
| 35 | + var baseJob = Job.ShortRun |
| 36 | + .With(CsProjCoreToolchain.Current.Value) |
| 37 | + .With(Platform.X64) |
| 38 | + .With(Jit.RyuJit) |
| 39 | + .With(Runtime.Core); |
| 40 | + Add(MemoryDiagnoser.Default); |
| 41 | + Add(baseJob.WithCustomBuildConfiguration("Release").WithId("Project")); |
| 42 | + Add(baseJob.WithCustomBuildConfiguration("ReleaseNuGet").WithId("NuGet")); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + const string ConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey"; |
| 47 | + |
| 48 | + [Params("int", "bigint", "varchar(10) character set utf8")] |
| 49 | + public string DataType { get; set; } |
| 50 | + |
| 51 | + [GlobalSetup(Target = nameof(Fetch200k))] |
| 52 | + public void Fetch200kSetup() |
| 53 | + { |
| 54 | + FbConnection.CreateDatabase(ConnectionString, true); |
| 55 | + using (var conn = new FbConnection(ConnectionString)) |
| 56 | + { |
| 57 | + conn.Open(); |
| 58 | + using (var cmd = conn.CreateCommand()) |
| 59 | + { |
| 60 | + cmd.CommandText = $"create table foobar (x {DataType})"; |
| 61 | + cmd.ExecuteNonQuery(); |
| 62 | + } |
| 63 | + using (var cmd = conn.CreateCommand()) |
| 64 | + { |
| 65 | + cmd.CommandText = @"execute block as |
| 66 | +declare cnt int; |
| 67 | +begin |
| 68 | + cnt = 200000; |
| 69 | + while (cnt > 0) do |
| 70 | + begin |
| 71 | + insert into foobar values (:cnt); |
| 72 | + cnt = cnt - 1; |
| 73 | + end |
| 74 | +end"; |
| 75 | + cmd.ExecuteNonQuery(); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + [Benchmark] |
| 81 | + public void Fetch200k() |
| 82 | + { |
| 83 | + using (var conn = new FbConnection(ConnectionString)) |
| 84 | + { |
| 85 | + conn.Open(); |
| 86 | + using (var cmd = conn.CreateCommand()) |
| 87 | + { |
| 88 | + cmd.CommandText = "select x from foobar"; |
| 89 | + using (var reader = cmd.ExecuteReader()) |
| 90 | + { |
| 91 | + while (reader.Read()) |
| 92 | + { |
| 93 | + var dummy = reader[0]; |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + [GlobalCleanup(Target = nameof(Fetch200k))] |
| 101 | + public void Fetch200kCleanup() |
| 102 | + { |
| 103 | + FbConnection.ClearAllPools(); |
| 104 | + FbConnection.DropDatabase(ConnectionString); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments