Skip to content

Commit cdc04be

Browse files
committed
Add comparison benchmarking
1 parent 652408e commit cdc04be

11 files changed

Lines changed: 141 additions & 44 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ permissions:
99
deployments: write
1010

1111
jobs:
12+
comparison:
13+
name: Comparison Marshalling
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-dotnet@v3
18+
with:
19+
dotnet-version: 8.0.x
20+
- name: Run
21+
run: dotnet run --project tests/DynamoDBGenerator.SourceGenerator.Benchmarks --configuration 'Release' -- --exporters 'JSON' --filter '*Marshalling.Comparison*' --memory --job 'Default'
22+
- name: Store
23+
uses: rhysd/github-action-benchmark@v1
24+
with:
25+
name: Comparison Marshalling
26+
tool: 'benchmarkdotnet'
27+
output-file-path: BenchmarkDotNet.Artifacts/results/DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.TemporalBenchmarks-report-full-compressed.json
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
auto-push: true
30+
benchmark-data-dir-path: 'benchmarks/marshalling/comparison'
31+
comment-on-alert: false
32+
fail-on-alert: false
33+
alert-comment-cc-users: '@inputfalken'
1234
temporal:
1335
name: Temporal Marshalling
1436
runs-on: ubuntu-latest

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/Marshalling/CollectionBenchmarks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Amazon.DynamoDBv2.Model;
22
using BenchmarkDotNet.Attributes;
33
using DynamoDBGenerator.Attributes;
4+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions;
5+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
46

57
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;
68

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Amazon.DynamoDBv2.Model;
2+
using BenchmarkDotNet.Attributes;
3+
using DynamoDBGenerator.Attributes;
4+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions;
5+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
6+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
7+
8+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Comparison;
9+
10+
[DynamoDBMarshaller(EntityType = typeof(Person))]
11+
public partial class Amazon
12+
{
13+
private readonly AWSComparisonBenchmarkHelper<Person, Person, PersonNames, PersonValues> _marshaller = PersonMarshaller.ToAwsComparisonHelper();
14+
15+
[Benchmark(Baseline = true)]
16+
public Person Unmarshall_Person_DTO() => _marshaller.Unmarshall();
17+
18+
[Benchmark(Baseline = true)]
19+
public Dictionary<string, AttributeValue> Marshall_Person_DTO() => _marshaller.Marshall();
20+
21+
[Benchmark]
22+
public Person AWS_Unmarshall_Person_DTO() => _marshaller.Unmarshall_AWS();
23+
24+
[Benchmark]
25+
public Dictionary<string, AttributeValue> AWS_Marshall_Person_DTO() => _marshaller.Marshall_AWS();
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
2+
3+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions;
4+
5+
public static class Extensions
6+
{
7+
public static DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4> ToBenchmarkHelper<T, T2, T3, T4>(
8+
this IDynamoDBMarshaller<T, T2, T3, T4> marshaller) where T3 : IAttributeExpressionNameTracker
9+
where T4 : IAttributeExpressionValueTracker<T2>
10+
{
11+
return new DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>(marshaller);
12+
}
13+
14+
public static AWSComparisonBenchmarkHelper<T, T2, T3, T4> ToAwsComparisonHelper<T, T2, T3, T4>(
15+
this IDynamoDBMarshaller<T, T2, T3, T4> marshaller) where T3 : IAttributeExpressionNameTracker
16+
where T4 : IAttributeExpressionValueTracker<T2>
17+
{
18+
return new AWSComparisonBenchmarkHelper<T, T2, T3, T4>(marshaller);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Runtime.CompilerServices;
2+
using Amazon;
3+
using Amazon.DynamoDBv2;
4+
using Amazon.DynamoDBv2.DataModel;
5+
using Amazon.DynamoDBv2.Model;
6+
using AutoFixture;
7+
8+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
9+
10+
public class AWSComparisonBenchmarkHelper<T, T2, T3, T4>
11+
where T4 : IAttributeExpressionValueTracker<T2>
12+
where T3 : IAttributeExpressionNameTracker
13+
{
14+
private readonly IDynamoDBMarshaller<T, T2, T3, T4> _marshaller;
15+
private readonly T _element;
16+
private readonly Dictionary<string, AttributeValue> _attributeValues;
17+
18+
private readonly DynamoDBContext _context;
19+
20+
private readonly ToDocumentConfig _dynamoDbOperationConfig;
21+
22+
public AWSComparisonBenchmarkHelper(IDynamoDBMarshaller<T, T2, T3, T4> marshaller)
23+
{
24+
_marshaller = marshaller;
25+
_element = SetupFixture().Create<T>();
26+
_attributeValues = marshaller.Marshall(_element);
27+
_dynamoDbOperationConfig = new ToDocumentConfig { Conversion = DynamoDBEntryConversion.V2 };
28+
_context = new DynamoDBContextBuilder()
29+
.WithDynamoDBClient(() => new AmazonDynamoDBClient(RegionEndpoint.EUWest1))
30+
.Build();
31+
}
32+
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34+
public T Unmarshall() => _marshaller.Unmarshall(_attributeValues);
35+
36+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
public Dictionary<string, AttributeValue> Marshall() => _marshaller.Marshall(_element);
38+
39+
40+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
41+
public Dictionary<string, AttributeValue> Marshall_AWS() => _context
42+
.ToDocument(_element, _dynamoDbOperationConfig)
43+
.ToAttributeMap(_dynamoDbOperationConfig.Conversion);
44+
45+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46+
public T Unmarshall_AWS() =>
47+
_context.FromDocument<T>(Amazon.DynamoDBv2.DocumentModel.Document.FromAttributeMap(_attributeValues));
48+
49+
private static Fixture SetupFixture()
50+
{
51+
var fixture = new Fixture();
52+
fixture.Customize<DateOnly>(o => o.FromFactory((DateTime dt) => DateOnly.FromDateTime(dt)));
53+
fixture.Customize<TimeOnly>(o => o.FromFactory((DateTime dt) => TimeOnly.FromDateTime(dt)));
54+
// Allow recursive types
55+
fixture.Behaviors
56+
.OfType<ThrowingRecursionBehavior>()
57+
.ToList()
58+
.ForEach(b => fixture.Behaviors.Remove(b));
59+
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
60+
return fixture;
61+
}
62+
}

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/Marshalling/BenchmarkHelper.cs renamed to tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/Marshalling/Extensions/Types/DynamoDbMarshallerBenchmarkHelper.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Amazon.DynamoDBv2.Model;
33
using AutoFixture;
44

5-
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;
5+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
66

7-
public class DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>
7+
public class DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>
88
where T4 : IAttributeExpressionValueTracker<T2>
99
where T3 : IAttributeExpressionNameTracker
1010
{
@@ -38,14 +38,4 @@ private static Fixture SetupFixture()
3838
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
3939
return fixture;
4040
}
41-
}
42-
43-
public static class Extensions
44-
{
45-
public static DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4> ToBenchmarkHelper<T, T2, T3, T4>(
46-
this IDynamoDBMarshaller<T, T2, T3, T4> marshaller) where T3 : IAttributeExpressionNameTracker
47-
where T4 : IAttributeExpressionValueTracker<T2>
48-
{
49-
return new DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>(marshaller);
50-
}
5141
}

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/Marshalling/PrimitiveBenchmarks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Amazon.DynamoDBv2.Model;
22
using BenchmarkDotNet.Attributes;
33
using DynamoDBGenerator.Attributes;
4+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions;
5+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
46

57
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;
68

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/Marshalling/TemporalBenchmarks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Amazon.DynamoDBv2.Model;
22
using BenchmarkDotNet.Attributes;
33
using DynamoDBGenerator.Attributes;
4+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions;
5+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Extensions.Types;
46

57
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;
68

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Benchmarks/SG_VS_AWS_Benchmarker.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public sealed record Address
88

99
public PostalCode PostalCode { get; set; } = null!;
1010

11-
public List<PersonEntity> Neighbours { get; set; } = null!;
11+
public List<Person> Neighbours { get; set; } = null!;
1212
}

0 commit comments

Comments
 (0)