-
Notifications
You must be signed in to change notification settings - Fork 0
/
NestedClassMappingDeserialization.cs
73 lines (63 loc) · 1.82 KB
/
NestedClassMappingDeserialization.cs
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
using System.Text.Json;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using AutoFixture;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Jobs;
using NServiceBus.Persistence.DynamoDB;
namespace DynamoDBMappingPerf;
[Config(typeof(Config))]
public class NestedClassMappingDeserialization
{
private Fixture? fixture;
private Dictionary<string,AttributeValue>? attributeMap;
class Config : ManualConfig
{
public Config()
{
AddDiagnoser(MemoryDiagnoser.Default);
AddJob(Job.Default.WithUnrollFactor(1500));
}
}
[GlobalSetup]
public void GlobalSetup()
{
// always five items in list etc.
fixture = new Fixture { RepeatCount = 5 };
}
[IterationSetup]
public void IterationSetup()
{
var nested = fixture.Create<Nested>();
var jsonString = JsonSerializer.Serialize(nested);
var doc = Document.FromJson(jsonString);
attributeMap = doc.ToAttributeMap();
}
[Benchmark(Baseline = true)]
public Nested? Deserialize_SDK()
{
var document = Document.FromAttributeMap(attributeMap);
var jsonString = document.ToJson();
return JsonSerializer.Deserialize<Nested>(jsonString);
}
[Benchmark]
public Nested? Deserialize_Manual()
{
return Mapper.ToObject<Nested>(attributeMap!);
}
public class Nested
{
public string? String { get; set; }
public Guid Guid { get; set; }
public bool Boolean { get; set; }
public List<DeeperNested>? DeeperNested { get; set; }
}
public class DeeperNested
{
public string? String { get; set; }
public Guid Guid { get; set; }
public bool Boolean { get; set; }
}
}