forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGetFieldValue.cs
More file actions
38 lines (30 loc) · 976 Bytes
/
GetFieldValue.cs
File metadata and controls
38 lines (30 loc) · 976 Bytes
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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
namespace Npgsql.Benchmarks;
[Config(typeof(Config))]
public class GetFieldValue
{
readonly NpgsqlConnection _conn;
readonly NpgsqlCommand _cmd;
readonly NpgsqlDataReader _reader;
public GetFieldValue()
{
_conn = BenchmarkEnvironment.OpenConnection();
_cmd = new NpgsqlCommand("SELECT 0, 'str'", _conn);
_reader = _cmd.ExecuteReader();
_reader.Read();
}
[Benchmark]
public void NullableField() => _reader.GetFieldValue<int?>(0);
[Benchmark]
public void ValueTypeField() => _reader.GetFieldValue<int>(0);
[Benchmark]
public void ReferenceTypeField() => _reader.GetFieldValue<string>(1);
[Benchmark]
public void ObjectField() => _reader.GetFieldValue<object>(1);
class Config : ManualConfig
{
public Config() => AddColumn(StatisticColumn.OperationsPerSecond);
}
}