Skip to content

Commit c51327a

Browse files
committed
Combine benchmarks into one class
1 parent 5499a1e commit c51327a

6 files changed

Lines changed: 128 additions & 50 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
with:
5858
name: Benchmark.Net Benchmark
5959
tool: 'benchmarkdotnet'
60-
output-file-path: tests/DynamoDBGenerator.SourceGenerator.Benchmarks/BenchmarkDotNet.Artifacts/results/Sample.Benchmarks-report-full-compressed.json
60+
output-file-path: tests/DynamoDBGenerator.SourceGenerator.Benchmarks/DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.TemporalBenchmarks-report-full-compressed.json
6161
github-token: ${{ secrets.GITHUB_TOKEN }}
6262
auto-push: true
6363
# Show alert with commit comment on detecting possible performance regression

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Collections;
44

55
[DynamoDBMarshaller(EntityType = typeof(Container<List<string>>))]
6-
public partial class StringList() : SG_VS_AWS_Benchmarker<Container<List<string>>>(
6+
public partial class StringList() : SG_BenchMarker<Container<List<string>>>(
77
ContainerMarshaller.Marshall,
88
ContainerMarshaller.Unmarshall
99
);
1010

1111
[DynamoDBMarshaller(EntityType = typeof(Container<Dictionary<string, int>>))]
12-
public partial class StringIntDictionary() : SG_VS_AWS_Benchmarker<Container<Dictionary<string, int>>>(
12+
public partial class StringIntDictionary() : SG_BenchMarker<Container<Dictionary<string, int>>>(
1313
ContainerMarshaller.Marshall,
1414
ContainerMarshaller.Unmarshall
1515
);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Runtime.CompilerServices;
2+
using Amazon.DynamoDBv2.Model;
3+
using AutoFixture;
4+
5+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Temporal;
6+
7+
public class DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4> where T4 : IAttributeExpressionValueTracker<T2>
8+
where T3 : IAttributeExpressionNameTracker
9+
{
10+
private readonly IDynamoDBMarshaller<T, T2, T3, T4> _marshaller;
11+
private readonly T _element;
12+
private readonly Dictionary<string, AttributeValue> _attributevalues;
13+
14+
public DynamoDbMarshallerBenchmarkHelper(IDynamoDBMarshaller<T, T2, T3, T4> marshaller)
15+
{
16+
_marshaller = marshaller;
17+
_element = SetupFixture().Create<T>();
18+
_attributevalues = marshaller.Marshall(_element);
19+
}
20+
21+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22+
public T Unmarshall() => _marshaller.Unmarshall(_attributevalues);
23+
24+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
25+
public Dictionary<string, AttributeValue> Marshall() => _marshaller.Marshall(_element);
26+
27+
private Fixture SetupFixture()
28+
{
29+
var fixture = new Fixture();
30+
fixture.Customize<DateOnly>(o => o.FromFactory((DateTime dt) => DateOnly.FromDateTime(dt)));
31+
fixture.Customize<TimeOnly>(o => o.FromFactory((DateTime dt) => TimeOnly.FromDateTime(dt)));
32+
// Allow recursive types
33+
fixture.Behaviors
34+
.OfType<ThrowingRecursionBehavior>()
35+
.ToList()
36+
.ForEach(b => fixture.Behaviors.Remove(b));
37+
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
38+
return fixture;
39+
}
40+
}
41+
42+
public static class Extensions
43+
{
44+
public static DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4> ToBenchmarkHelper<T, T2, T3, T4>(
45+
this IDynamoDBMarshaller<T, T2, T3, T4> marshaller) where T3 : IAttributeExpressionNameTracker
46+
where T4 : IAttributeExpressionValueTracker<T2>
47+
{
48+
return new DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>(marshaller);
49+
}
50+
}
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
11
using System;
2+
using Amazon.DynamoDBv2.Model;
3+
using BenchmarkDotNet.Attributes;
24
using DynamoDBGenerator.Attributes;
35

46
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Primitive;
57

6-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Boolean>))]
7-
public partial class Bool() : SG_VS_AWS_Benchmarker<Container<System.Boolean>>(
8+
9+
[DynamoDBMarshaller(EntityType = typeof(Container<Boolean>))]
10+
public partial class System_Bool() : SG_BenchMarker<Container<Boolean>>(
811
ContainerMarshaller.Marshall,
912
ContainerMarshaller.Unmarshall
1013
);
1114

12-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Char>))]
13-
public partial class Char() : SG_VS_AWS_Benchmarker<Container<System.Char>>(
15+
[DynamoDBMarshaller(EntityType = typeof(Container<Char>))]
16+
public partial class System_Char() : SG_BenchMarker<Container<Char>>(
1417
ContainerMarshaller.Marshall,
1518
ContainerMarshaller.Unmarshall
1619
);
1720

18-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Int32>))]
19-
public partial class Int32() : SG_VS_AWS_Benchmarker<Container<System.Int32>>(
21+
[DynamoDBMarshaller(EntityType = typeof(Container<Int32>))]
22+
public partial class System_Int32() : SG_BenchMarker<Container<Int32>>(
2023
ContainerMarshaller.Marshall,
2124
ContainerMarshaller.Unmarshall
2225
);
2326

24-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Int64>))]
25-
public partial class Int64() : SG_VS_AWS_Benchmarker<Container<System.Int64>>(
27+
[DynamoDBMarshaller(EntityType = typeof(Container<Int64>))]
28+
public partial class System_Int64() : SG_BenchMarker<Container<Int64>>(
2629
ContainerMarshaller.Marshall,
2730
ContainerMarshaller.Unmarshall
2831
);
2932

30-
[DynamoDBMarshaller(EntityType = typeof(Container<System.String>))]
31-
public partial class String_() : SG_VS_AWS_Benchmarker<Container<System.String>>(
33+
[DynamoDBMarshaller(EntityType = typeof(Container<String>))]
34+
public partial class System_String() : SG_BenchMarker<Container<String>>(
3235
ContainerMarshaller.Marshall,
3336
ContainerMarshaller.Unmarshall
3437
);
3538

36-
[DynamoDBMarshaller(EntityType = typeof(Container<System.UInt32>))]
37-
public partial class UInt32() : SG_VS_AWS_Benchmarker<Container<System.UInt32>>(
39+
[DynamoDBMarshaller(EntityType = typeof(Container<UInt32>))]
40+
public partial class System_UInt32() : SG_BenchMarker<Container<UInt32>>(
3841
ContainerMarshaller.Marshall,
3942
ContainerMarshaller.Unmarshall
4043
);
4144

42-
[DynamoDBMarshaller(EntityType = typeof(Container<System.UInt64>))]
43-
public partial class UInt64() : SG_VS_AWS_Benchmarker<Container<System.UInt64>>(
45+
[DynamoDBMarshaller(EntityType = typeof(Container<UInt64>))]
46+
public partial class System_UInt64() : SG_BenchMarker<Container<UInt64>>(
4447
ContainerMarshaller.Marshall,
4548
ContainerMarshaller.Unmarshall
4649
);
4750

48-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Guid>))]
49-
public partial class Guid() : SG_VS_AWS_Benchmarker<Container<System.Guid>>(
51+
[DynamoDBMarshaller(EntityType = typeof(Container<Guid>))]
52+
public partial class System_Guid() : SG_BenchMarker<Container<Guid>>(
5053
ContainerMarshaller.Marshall,
5154
ContainerMarshaller.Unmarshall
5255
);
5356

54-
[DynamoDBMarshaller(EntityType = typeof(Container<System.DayOfWeek>))]
55-
public partial class Test() : SG_VS_AWS_Benchmarker<Container<System.DayOfWeek>>(
57+
[DynamoDBMarshaller(EntityType = typeof(Container<DayOfWeek>))]
58+
public partial class System_Enum() : SG_BenchMarker<Container<DayOfWeek>>(
5659
ContainerMarshaller.Marshall,
5760
ContainerMarshaller.Unmarshall
5861
);
5962

60-
[DynamoDBMarshaller(EntityType = typeof(Container<System.Double>))]
61-
public partial class Double() : SG_VS_AWS_Benchmarker<Container<System.Double>>(
63+
[DynamoDBMarshaller(EntityType = typeof(Container<Double>))]
64+
public partial class System_Double() : SG_BenchMarker<Container<Double>>(
6265
ContainerMarshaller.Marshall,
6366
ContainerMarshaller.Unmarshall
6467
);

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

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Amazon.DynamoDBv2.Model;
2+
using BenchmarkDotNet.Attributes;
3+
using DynamoDBGenerator.Attributes;
4+
5+
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.Temporal;
6+
7+
[DynamoDBMarshaller(EntityType = typeof(Container<DateTime>), AccessName = "DateTimeMarshaller")]
8+
[DynamoDBMarshaller(EntityType = typeof(Container<DateTimeOffset>), AccessName = "DateTimeOffsetMarshaller")]
9+
[DynamoDBMarshaller(EntityType = typeof(Container<DateOnly>), AccessName = "DateOnlyMarshaller")]
10+
[DynamoDBMarshaller(EntityType = typeof(Container<TimeOnly>), AccessName = "TimeOnlyMarshaller")]
11+
public sealed partial class TemporalBenchmarks
12+
{
13+
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateTime>, Container<DateTime>, ContainerDateTimeNames,
14+
ContainerDateTimeValues> _dateTime = DateTimeMarshaller.ToBenchmarkHelper();
15+
16+
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateTimeOffset>, Container<DateTimeOffset>,
17+
ContainerDateTimeOffsetNames, ContainerDateTimeOffsetValues> _dateTimeOffset =
18+
DateTimeOffsetMarshaller.ToBenchmarkHelper();
19+
20+
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateOnly>, Container<DateOnly>, ContainerDateOnlyNames,
21+
ContainerDateOnlyValues> _dateOnly =
22+
DateOnlyMarshaller.ToBenchmarkHelper();
23+
24+
private readonly DynamoDbMarshallerBenchmarkHelper<Container<TimeOnly>, Container<TimeOnly>, ContainerTimeOnlyNames,
25+
ContainerTimeOnlyValues> _timeOnly =
26+
TimeOnlyMarshaller.ToBenchmarkHelper();
27+
28+
29+
[Benchmark]
30+
public Container<TimeOnly> Unmarshall_TimeOnly() => _timeOnly.Unmarshall();
31+
32+
[Benchmark]
33+
public Dictionary<string, AttributeValue> Marshall_TimeOnly() => _timeOnly.Marshall();
34+
35+
[Benchmark]
36+
public Container<DateOnly> Unmarshall_DateOnly() => _dateOnly.Unmarshall();
37+
38+
[Benchmark]
39+
public Dictionary<string, AttributeValue> Marshall_DateOnly() => _dateOnly.Marshall();
40+
41+
[Benchmark]
42+
public Container<DateTimeOffset> Unmarshall_DateTimeOffset() => _dateTimeOffset.Unmarshall();
43+
44+
[Benchmark]
45+
public Dictionary<string, AttributeValue> Marshall_DateTimeOffset() => _dateTimeOffset.Marshall();
46+
47+
[Benchmark]
48+
public Container<DateTime> Unmarshall_DateTime() => _dateTime.Unmarshall();
49+
50+
[Benchmark]
51+
public Dictionary<string, AttributeValue> Marshall_DateTime() => _dateTime.Marshall();
52+
}

0 commit comments

Comments
 (0)