forked from roji/Npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteStringsVaryingLengths.cs
More file actions
92 lines (79 loc) · 2.46 KB
/
WriteStringsVaryingLengths.cs
File metadata and controls
92 lines (79 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using NpgsqlTypes;
namespace Npgsql.Benchmarks.Types
{
[Config(typeof(Config))]
public class WriteStringsVaryingLengths
{
readonly NpgsqlConnection _conn;
NpgsqlCommand _intCmd;
NpgsqlCommand _text1Cmd;
NpgsqlCommand _text100Cmd;
NpgsqlCommand _text1000Cmd;
NpgsqlCommand _text10000Cmd;
#region Initialization
public WriteStringsVaryingLengths()
{
_conn = BenchmarkEnvironment.OpenConnection();
using (var cmd = new NpgsqlCommand("CREATE TEMP TABLE foo (int INT, text TEXT)", _conn))
cmd.ExecuteNonQuery();
_intCmd = BuildCommand("int", NpgsqlDbType.Integer, 8);
_text1Cmd = BuildCommand("text", NpgsqlDbType.Text, new string('x', 1));
_text100Cmd = BuildCommand("text", NpgsqlDbType.Text, new string('x', 100));
_text1000Cmd = BuildCommand("text", NpgsqlDbType.Text, new string('x', 1000));
_text10000Cmd = BuildCommand("text", NpgsqlDbType.Text, new string('x', 10000));
}
[GlobalSetup]
public void Setup()
{
using (var cmd = new NpgsqlCommand("TRUNCATE foo", _conn))
cmd.ExecuteNonQuery();
}
NpgsqlCommand BuildCommand(string column, NpgsqlDbType npgsqlDbType, object value)
{
var cmd = new NpgsqlCommand($"INSERT INTO foo ({column}) VALUES (@p)", _conn);
cmd.Parameters.AddWithValue("p", npgsqlDbType, value);
return cmd;
}
#endregion
[Benchmark]
public void Int()
{
_intCmd.ExecuteNonQuery();
}
[Benchmark]
public void Text1()
{
_text1Cmd.ExecuteNonQuery();
}
[Benchmark]
public void Text100()
{
_text100Cmd.ExecuteNonQuery();
}
[Benchmark]
public void Text1000()
{
_text1000Cmd.ExecuteNonQuery();
}
[Benchmark]
public void Text10000()
{
_text10000Cmd.ExecuteNonQuery();
}
class Config : ManualConfig
{
public Config()
{
Add(StatisticColumn.OperationsPerSecond);
}
}
}
}