-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathResolveHandler.cs
More file actions
40 lines (32 loc) · 1.22 KB
/
ResolveHandler.cs
File metadata and controls
40 lines (32 loc) · 1.22 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
using BenchmarkDotNet.Attributes;
using Npgsql.Internal;
using Npgsql.Internal.Postgres;
namespace Npgsql.Benchmarks;
[MemoryDiagnoser]
public class ResolveHandler
{
PgSerializerOptions _serializerOptions = null!;
[Params(0, 1, 2)]
public int NumPlugins { get; set; }
[GlobalSetup]
public void Setup()
{
var dataSourceBuilder = new NpgsqlDataSourceBuilder();
if (NumPlugins > 0)
dataSourceBuilder.UseNodaTime();
if (NumPlugins > 1)
dataSourceBuilder.UseNetTopologySuite();
// Alternatively we must build a data source and get it bootstrapped against a real database.
(_, var config) = dataSourceBuilder.PrepareConfiguration();
_serializerOptions = new PgSerializerOptions(PostgresMinimalDatabaseInfo.DefaultTypeCatalog, config.ResolverChain);
}
[Benchmark]
public PgTypeInfo? ResolveDefault()
=> _serializerOptions.GetTypeInfoInternal(null, new Oid(23)); // int4
[Benchmark]
public PgTypeInfo? ResolveType()
=> _serializerOptions.GetTypeInfoInternal(typeof(int), null);
[Benchmark]
public PgTypeInfo? ResolveBoth()
=> _serializerOptions.GetTypeInfoInternal(typeof(int), new Oid(23)); // int4
}