Skip to content

Commit 2576eed

Browse files
committed
Include benchmark result
1 parent fc49b6e commit 2576eed

File tree

6 files changed

+81
-66
lines changed

6 files changed

+81
-66
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ The source generator will look for attributes and implement interfaces that exis
3434
* Simplify Attribute Expressions: Easily create complex expressions with an intuitive approach.
3535
* Faster performance: Utilize the low-level API that would normally be implemented manually.
3636

37+
## [Benchmarks](tests/DynamoDBGenerator.SourceGenerator.Benchmarks):
38+
39+
Here's a quick summary about how this library performs with a quick example of marshalling and unmarshalling a simple DTO object.
40+
41+
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
42+
|---------------------------- |-----------:|---------:|---------:|-------:|-------:|----------:|
43+
| Marshall_AWS_Reflection | 2,467.8 ns | 48.87 ns | 68.51 ns | 0.5112 | 0.0038 | 6450 B |
44+
| Marshall_Source_Generated | 234.0 ns | 2.92 ns | 2.73 ns | 0.1421 | 0.0010 | 1784 B |
45+
| Unmarshall_AWS_Reflection | 2,397.0 ns | 36.13 ns | 30.17 ns | 0.5188 | 0.0038 | 6544 B |
46+
| Unmarshall_Source_Generated | 131.6 ns | 0.82 ns | 0.77 ns | 0.0126 | - | 160 B |
47+
3748
## Features:
3849

3950
* Reflection-Free Codebase: The generated code is built without reliance on reflection, ensuring compatibility with
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Amazon;
2+
using Amazon.DynamoDBv2;
3+
using Amazon.DynamoDBv2.DataModel;
4+
using Amazon.DynamoDBv2.DocumentModel;
5+
using Amazon.DynamoDBv2.Model;
6+
using AutoFixture;
7+
using BenchmarkDotNet.Attributes;
8+
using BenchmarkDotNet.Jobs;
9+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
10+
11+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks;
12+
13+
[SimpleJob(RuntimeMoniker.Net80)]
14+
[MemoryDiagnoser]
15+
public class MarshallBenchmark
16+
{
17+
private readonly DynamoDBContext _context;
18+
private readonly ToDocumentConfig _dynamoDbOperationConfig;
19+
private readonly PersonEntity _singleElement;
20+
private readonly Dictionary<string, AttributeValue> _attributeValues;
21+
22+
public MarshallBenchmark()
23+
{
24+
var fixture = new Fixture();
25+
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => fixture.Behaviors.Remove(b));
26+
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
27+
28+
_context = new DynamoDBContextBuilder()
29+
.WithDynamoDBClient(() => new AmazonDynamoDBClient(RegionEndpoint.EUWest1))
30+
.Build();
31+
_dynamoDbOperationConfig = new()
32+
{
33+
Conversion = DynamoDBEntryConversion.V2
34+
};
35+
36+
_singleElement = fixture.Create<PersonEntity>();
37+
_attributeValues = _context.ToDocument(_singleElement).ToAttributeMap();
38+
}
39+
40+
41+
[Benchmark]
42+
public Dictionary<string, AttributeValue> Marshall_AWS_Reflection()
43+
{
44+
return _context.ToDocument(_singleElement, _dynamoDbOperationConfig)
45+
.ToAttributeMap(_dynamoDbOperationConfig.Conversion);
46+
}
47+
48+
[Benchmark]
49+
public Dictionary<string, AttributeValue> Marshall_Source_Generated()
50+
{
51+
return PersonEntity.PersonEntityMarshaller.Marshall(_singleElement);
52+
}
53+
54+
[Benchmark]
55+
public PersonEntity Unmarshall_AWS_Reflection()
56+
{
57+
return _context.FromDocument<PersonEntity>(Document.FromAttributeMap(_attributeValues));
58+
}
59+
60+
[Benchmark]
61+
public PersonEntity Unmarshall_Source_Generated()
62+
{
63+
return PersonEntity.PersonEntityMarshaller.Unmarshall(_attributeValues);
64+
}
65+
}

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/Address.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
22

3-
public class Address
3+
public sealed record Address
44
{
55
public string Id { get; set; } = null!;
66

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PersonEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
44

55

66
[DynamoDBMarshaller(EntityType = typeof(PersonEntity))]
7-
public partial class PersonEntity
7+
public partial record PersonEntity
88
{
99
[DynamoDBHashKey]
1010
public string Id { get; set; } = null!;

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PostalCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
22

3-
public class PostalCode
3+
public sealed class PostalCode
44
{
55
public string ZipCode { get; set; } = null!;
66
public string Town { get; set; } = null!;
Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,7 @@
11
// See https://aka.ms/new-console-template for more information
22

3-
using Amazon;
4-
using Amazon.DynamoDBv2;
5-
using Amazon.DynamoDBv2.DataModel;
6-
using Amazon.DynamoDBv2.DocumentModel;
7-
using Amazon.DynamoDBv2.Model;
8-
using AutoFixture;
9-
using BenchmarkDotNet.Attributes;
10-
using BenchmarkDotNet.Jobs;
3+
114
using BenchmarkDotNet.Running;
12-
using DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
135
using DynamoDBGenerator.SourceGenerator.Benchmarks;
146

15-
16-
BenchmarkRunner.Run<Marshalling>();
17-
18-
[SimpleJob(RuntimeMoniker.Net80)]
19-
[MemoryDiagnoser]
20-
public class Marshalling
21-
{
22-
private readonly DynamoDBContext _context;
23-
private readonly DynamoDBOperationConfig _dynamoDbOperationConfig;
24-
private readonly PersonEntity _singleElement;
25-
private readonly Dictionary<string, AttributeValue> _attributeValues;
26-
27-
public Marshalling()
28-
{
29-
var fixture = new Fixture();
30-
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => fixture.Behaviors.Remove(b));
31-
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
32-
33-
_context = new(new AmazonDynamoDBClient(RegionEndpoint.EUWest1));
34-
_dynamoDbOperationConfig = new()
35-
{
36-
Conversion = DynamoDBEntryConversion.V2
37-
};
38-
39-
_singleElement = fixture.Create<PersonEntity>();
40-
_attributeValues = _context.ToDocument(_singleElement).ToAttributeMap();
41-
}
42-
43-
44-
[Benchmark]
45-
public Dictionary<string, AttributeValue> Marshall_AWS()
46-
{
47-
return _context.ToDocument(_singleElement, _dynamoDbOperationConfig).ToAttributeMap(_dynamoDbOperationConfig.Conversion);
48-
}
49-
50-
[Benchmark]
51-
public Dictionary<string, AttributeValue> Marshall_SG()
52-
{
53-
return PersonEntity.PersonEntityMarshaller.Marshall(_singleElement);
54-
}
55-
56-
[Benchmark]
57-
public PersonEntity Unmarshall_AWS()
58-
{
59-
return _context.FromDocument<PersonEntity>(Document.FromAttributeMap(_attributeValues));
60-
}
61-
62-
[Benchmark]
63-
public PersonEntity Unmarshall_SG()
64-
{
65-
return PersonEntity.PersonEntityMarshaller.Unmarshall(_attributeValues);
66-
}
67-
68-
}
7+
BenchmarkRunner.Run<MarshallBenchmark>();

0 commit comments

Comments
 (0)