-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarshallBenchmark.cs
More file actions
66 lines (55 loc) · 2.05 KB
/
Copy pathMarshallBenchmark.cs
File metadata and controls
66 lines (55 loc) · 2.05 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
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using AutoFixture;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
namespace DynamoDBGenerator.SourceGenerator.Benchmarks;
[SimpleJob(RuntimeMoniker.Net80)]
[MemoryDiagnoser]
public class MarshallBenchmark
{
private readonly DynamoDBContext _context;
private readonly ToDocumentConfig _dynamoDbOperationConfig;
private readonly PersonEntity _singleElement;
private readonly Dictionary<string, AttributeValue> _attributeValues;
public MarshallBenchmark()
{
var fixture = new Fixture();
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
_context = new DynamoDBContextBuilder()
.WithDynamoDBClient(() => new AmazonDynamoDBClient(RegionEndpoint.EUWest1))
.Build();
_dynamoDbOperationConfig = new()
{
Conversion = DynamoDBEntryConversion.V2
};
_singleElement = fixture.Create<PersonEntity>();
_attributeValues = _context.ToDocument(_singleElement).ToAttributeMap();
}
[Benchmark]
public Dictionary<string, AttributeValue> Marshall_AWS_Reflection()
{
return _context.ToDocument(_singleElement, _dynamoDbOperationConfig)
.ToAttributeMap(_dynamoDbOperationConfig.Conversion);
}
[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Source_Generated()
{
return PersonEntity.PersonEntityMarshaller.Marshall(_singleElement);
}
[Benchmark]
public PersonEntity Unmarshall_AWS_Reflection()
{
return _context.FromDocument<PersonEntity>(Document.FromAttributeMap(_attributeValues));
}
[Benchmark]
public PersonEntity Unmarshall_Source_Generated()
{
return PersonEntity.PersonEntityMarshaller.Unmarshall(_attributeValues);
}
}