Skip to content

Commit 1b8642d

Browse files
committed
Update benchmarking rules
1 parent e99ec77 commit 1b8642d

8 files changed

Lines changed: 164 additions & 73 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,42 @@ jobs:
4141
- name: upload nuget package
4242
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
4343
run: dotnet nuget push nupkgs/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
44+
benchmark:
45+
name: Run Benchmark.Net benchmark example
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: actions/setup-dotnet@v3
50+
with:
51+
dotnet-version: 8.0.x
52+
- name: Run benchmark
53+
run: cd tests/DynamoDBGenerator.SourceGenerator.Benchmarks && dotnet run --exporters json --filter '*'
54+
55+
- name: Store benchmark result
56+
uses: rhysd/github-action-benchmark@v1
57+
with:
58+
name: Benchmark.Net Benchmark
59+
tool: 'benchmarkdotnet'
60+
output-file-path: examples/benchmarkdotnet/BenchmarkDotNet.Artifacts/results/Sample.Benchmarks-report-full-compressed.json
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
62+
auto-push: true
63+
# Show alert with commit comment on detecting possible performance regression
64+
alert-threshold: '200%'
65+
comment-on-alert: true
66+
fail-on-alert: true
67+
alert-comment-cc-users: '@inputfalken'
68+
69+
- name: Store benchmark result - separate results repo
70+
uses: rhysd/github-action-benchmark@v1
71+
with:
72+
name: Benchmark.Net Benchmark
73+
tool: 'benchmarkdotnet'
74+
output-file-path: examples/benchmarkdotnet/BenchmarkDotNet.Artifacts/results/Sample.Benchmarks-report-full-compressed.json
75+
github-token: ${{ secrets.BENCHMARK_ACTION_BOT_TOKEN }}
76+
auto-push: true
77+
# Show alert with commit comment on detecting possible performance regression
78+
alert-threshold: '200%'
79+
comment-on-alert: true
80+
fail-on-alert: true
81+
alert-comment-cc-users: '@inputfalken'
82+
gh-repository: 'github.com/benchmark-action/github-action-benchmark-results'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using DynamoDBGenerator.Attributes;
2+
3+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarkers;
4+
5+
[DynamoDBMarshaller(EntityType = typeof(Container<List<string>>))]
6+
public partial class StringList() : SG_VS_AWS_Benchmarker<Container<List<string>>>(
7+
ContainerMarshaller.Marshall,
8+
ContainerMarshaller.Unmarshall
9+
);
10+
11+
[DynamoDBMarshaller(EntityType = typeof(Container<Dictionary<string, int>>))]
12+
public partial class StringIntDictionary() : SG_VS_AWS_Benchmarker<Container<Dictionary<string, int>>>(
13+
ContainerMarshaller.Marshall,
14+
ContainerMarshaller.Unmarshall
15+
);
16+
17+
[DynamoDBMarshaller(EntityType = typeof(Container<HashSet<string>>))]
18+
public partial class StringHashSet() : SG_VS_AWS_Benchmarker<Container<HashSet<string>>>(
19+
ContainerMarshaller.Marshall,
20+
ContainerMarshaller.Unmarshall
21+
);
22+
23+
[DynamoDBMarshaller(EntityType = typeof(Container<HashSet<int>>))]
24+
public partial class IntHashSet() : SG_VS_AWS_Benchmarker<Container<HashSet<int>>>(
25+
ContainerMarshaller.Marshall,
26+
ContainerMarshaller.Unmarshall
27+
);
28+
29+
[DynamoDBMarshaller(EntityType = typeof(Container<List<KeyValuePair<string, int>>>))]
30+
public partial class KeyValuePairList() : SG_BenchMarker<Container<List<KeyValuePair<string, int>>>>(
31+
ContainerMarshaller.Marshall,
32+
ContainerMarshaller.Unmarshall
33+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarkers;
2+
3+
public sealed class Container<T>
4+
{
5+
public T Value { get; set; }
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using DynamoDBGenerator.SourceGenerator.Benchmarks.Models;
4+
5+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarkers.Dtos;
6+
7+
//[SimpleJob(RuntimeMoniker.Net80)]
8+
//[MemoryDiagnoser]
9+
//public class PersonBenchmarker() : MarshalBenchmarker<PersonEntity>(
10+
// PersonEntity.PersonEntityMarshaller.Marshall,
11+
// PersonEntity.PersonEntityMarshaller.Unmarshall
12+
//);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Amazon.DynamoDBv2.Model;
2+
using AutoFixture;
3+
using BenchmarkDotNet.Attributes;
4+
5+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarkers;
6+
7+
[ShortRunJob, MarkdownExporter, MemoryDiagnoser]
8+
public abstract class SG_BenchMarker<T>
9+
{
10+
private readonly Func<T, Dictionary<string, AttributeValue>> _marshaller;
11+
private readonly Func<Dictionary<string, AttributeValue>, T> _unMarshaller;
12+
protected readonly T SingleElement;
13+
protected readonly Dictionary<string, AttributeValue> AttributeValues;
14+
15+
protected SG_BenchMarker(
16+
Func<T, Dictionary<string, AttributeValue>> marshaller,
17+
Func<Dictionary<string, AttributeValue>, T> unMarshaller
18+
)
19+
{
20+
_marshaller = marshaller;
21+
_unMarshaller = unMarshaller;
22+
SingleElement = SetupFixture().Create<T>();
23+
AttributeValues = marshaller(SingleElement);
24+
}
25+
26+
[Benchmark]
27+
public Dictionary<string, AttributeValue> Marshall_Source_Generated() => _marshaller(SingleElement);
28+
29+
[Benchmark]
30+
public T Unmarshall_Source_Generated() => _unMarshaller(AttributeValues);
31+
32+
private static Fixture SetupFixture()
33+
{
34+
var fixture = new Fixture();
35+
36+
// Allow recursive types
37+
fixture.Behaviors
38+
.OfType<ThrowingRecursionBehavior>()
39+
.ToList()
40+
.ForEach(b => fixture.Behaviors.Remove(b));
41+
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
42+
return fixture;
43+
}
44+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Amazon;
2+
using Amazon.DynamoDBv2;
3+
using Amazon.DynamoDBv2.DataModel;
4+
using Amazon.DynamoDBv2.DocumentModel;
5+
using Amazon.DynamoDBv2.Model;
6+
using BenchmarkDotNet.Attributes;
7+
8+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarkers;
9+
10+
public abstract class SG_VS_AWS_Benchmarker<T>(
11+
Func<T, Dictionary<string, AttributeValue>> marshaller,
12+
Func<Dictionary<string, AttributeValue>, T> unMarshaller
13+
) : SG_BenchMarker<T>(marshaller, unMarshaller)
14+
{
15+
private readonly DynamoDBContext _context = new DynamoDBContextBuilder()
16+
.WithDynamoDBClient(() => new AmazonDynamoDBClient(RegionEndpoint.EUWest1))
17+
.Build();
18+
19+
private readonly ToDocumentConfig _dynamoDbOperationConfig = new() { Conversion = DynamoDBEntryConversion.V2 };
20+
21+
22+
[Benchmark]
23+
public Dictionary<string, AttributeValue> Marshall_AWS_Reflection() => _context
24+
.ToDocument(SingleElement, _dynamoDbOperationConfig)
25+
.ToAttributeMap(_dynamoDbOperationConfig.Conversion);
26+
27+
[Benchmark]
28+
public T Unmarshall_AWS_Reflection() => _context.FromDocument<T>(Document.FromAttributeMap(AttributeValues));
29+
}

tests/DynamoDBGenerator.SourceGenerator.Benchmarks/MarshallBenchmark.cs

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
4-
using BenchmarkDotNet.Running;
5-
using DynamoDBGenerator.SourceGenerator.Benchmarks;
6-
7-
BenchmarkRunner.Run<MarshallBenchmark>();
1+
BenchmarkDotNet.Running.BenchmarkRunner.Run(typeof(Program).Assembly);

0 commit comments

Comments
 (0)