Skip to content

Commit 831da19

Browse files
committed
Performance improvements
1 parent 6a76126 commit 831da19

12 files changed

Lines changed: 984 additions & 459 deletions

Soenneker.Gen.EnumValues.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
2828
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EUnitTestFramework_002ESettings_002EMigrations_002ERemoveBuildPolicyAlwaysMigration/@EntryIndexedValue">True</s:Boolean>
2929
<s:Int64 x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionDefault/OutputLineNumberLimit/@EntryValue">9999</s:Int64>
30+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Intellenum/@EntryIndexedValue">True</s:Boolean>
3031
<s:Boolean x:Key="/Default/UserDictionary/Words/=Soenneker/@EntryIndexedValue">True</s:Boolean>
3132
</wpf:ResourceDictionary>

src/Soenneker.Gen.EnumValues/EnumValueSourceGenerator.Emission.cs

Lines changed: 527 additions & 155 deletions
Large diffs are not rendered by default.

src/Soenneker.Gen.EnumValues/EnumValueSourceGenerator.SourceFragments.cs

Lines changed: 101 additions & 46 deletions
Large diffs are not rendered by default.

src/Soenneker.Gen.EnumValues/EnumValueSourceGenerator.cs

Lines changed: 298 additions & 203 deletions
Large diffs are not rendered by default.

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/BenchmarkRunner.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BenchmarkDotNet.Reports;
22
using Soenneker.Benchmarking.Extensions.Summary;
3+
using Soenneker.Facts.Local;
34
using Soenneker.Tests.Benchmark;
45
using System.Threading.Tasks;
56
using Xunit;
@@ -12,31 +13,31 @@ public BenchmarkRunner(ITestOutputHelper outputHelper) : base(outputHelper)
1213
{
1314
}
1415

15-
// [Fact]
16+
[LocalFact]
1617
public async ValueTask EnumValuesListBenchmark()
1718
{
1819
Summary summary = BenchmarkDotNet.Running.BenchmarkRunner.Run<EnumValuesListBenchmark>(DefaultConf);
1920

2021
await summary.OutputSummaryToLog(OutputHelper, CancellationToken);
2122
}
2223

23-
// [Fact]
24+
[LocalFact]
2425
public async ValueTask TryFromNameBenchmark()
2526
{
2627
Summary summary = BenchmarkDotNet.Running.BenchmarkRunner.Run<TryFromNameBenchmark>(DefaultConf);
2728

2829
await summary.OutputSummaryToLog(OutputHelper, CancellationToken);
2930
}
3031

31-
// [Fact]
32+
[LocalFact]
3233
public async ValueTask TryFromValueBenchmark()
3334
{
3435
Summary summary = BenchmarkDotNet.Running.BenchmarkRunner.Run<TryFromValueBenchmark>(DefaultConf);
3536

3637
await summary.OutputSummaryToLog(OutputHelper, CancellationToken);
3738
}
3839

39-
// [Fact]
40+
[LocalFact]
4041
public async ValueTask SerializationBenchmark()
4142
{
4243
Summary summary = BenchmarkDotNet.Running.BenchmarkRunner.Run<SerializationBenchmark>(DefaultConf);

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/ColorCodeIntIntellenum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public partial class ColorCodeIntIntellenum
1010
{
1111
public static readonly ColorCodeIntIntellenum Red = new(0);
1212
public static readonly ColorCodeIntIntellenum Blue = new(1);
13-
}
13+
}

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/ColorCodeIntellenum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public partial class ColorCodeIntellenum
1010
{
1111
public static readonly ColorCodeIntellenum Red = new("R");
1212
public static readonly ColorCodeIntellenum Blue = new("B");
13-
}
13+
}

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/EnumValuesListBenchmark.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ namespace Soenneker.Gen.EnumValues.Tests.Benchmarks;
88
public class EnumValuesListBenchmark
99
{
1010
[Benchmark(Baseline = true)]
11-
public System.Collections.Generic.IReadOnlyList<ColorCode> GenEnumValues_Small()
11+
public int GenEnumValues_Small()
1212
{
13-
return ColorCode.List;
13+
return ColorCode.List.Count;
1414
}
1515

16-
// [Benchmark]
17-
public System.Collections.Generic.IReadOnlyList<ColorCodeSmartEnum> SmartEnum_Small()
16+
[Benchmark]
17+
public int SmartEnum_Small()
1818
{
19-
return ColorCodeSmartEnum.List.ToList();
19+
return ColorCodeSmartEnum.List.Count;
2020
}
2121

2222
[Benchmark]
23-
public System.Collections.Generic.IEnumerable<ColorCodeIntellenum> Intellenum_Small()
23+
public int Intellenum_Small()
2424
{
25-
return ColorCodeIntellenum.List();
25+
return ColorCodeIntellenum.List().Count();
2626
}
2727

2828
//[Benchmark]
29-
public System.Collections.Generic.IReadOnlyList<ColorCodeLarge> GenEnumValues_Large()
30-
{
31-
return ColorCodeLarge.List;
32-
}
29+
//public int GenEnumValues_Large()
30+
//{
31+
// return ColorCodeLarge.List.Count;
32+
//}
3333
}

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/SerializationBenchmark.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string Intellenum_SystemTextJson_Serialize()
3434
return System.Text.Json.JsonSerializer.Serialize(_intellenumValue, _stjOptions);
3535
}
3636

37-
//[Benchmark]
37+
[Benchmark]
3838
public string SmartEnum_SystemTextJson_Serialize()
3939
{
4040
return System.Text.Json.JsonSerializer.Serialize(_smartEnumValue, _stjOptions);
@@ -52,45 +52,45 @@ public ColorCodeIntellenum Intellenum_SystemTextJson_Deserialize()
5252
return System.Text.Json.JsonSerializer.Deserialize<ColorCodeIntellenum>("\"R\"", _stjOptions)!;
5353
}
5454

55-
// [Benchmark]
55+
[Benchmark]
5656
public ColorCodeSmartEnum SmartEnum_SystemTextJson_Deserialize()
5757
{
5858
return System.Text.Json.JsonSerializer.Deserialize<ColorCodeSmartEnum>("\"R\"", _stjOptions)!;
5959
}
6060

61-
// [Benchmark]
62-
public string GenEnumValues_Newtonsoft_Serialize()
63-
{
64-
return JsonConvert.SerializeObject(_genValue);
65-
}
61+
//// [Benchmark]
62+
// public string GenEnumValues_Newtonsoft_Serialize()
63+
// {
64+
// return JsonConvert.SerializeObject(_genValue);
65+
// }
6666

67-
// [Benchmark]
68-
public string Intellenum_Newtonsoft_Serialize()
69-
{
70-
return JsonConvert.SerializeObject(_intellenumValue);
71-
}
67+
// // [Benchmark]
68+
// public string Intellenum_Newtonsoft_Serialize()
69+
// {
70+
// return JsonConvert.SerializeObject(_intellenumValue);
71+
// }
7272

73-
//[Benchmark]
74-
public string SmartEnum_Newtonsoft_Serialize()
75-
{
76-
return JsonConvert.SerializeObject(_smartEnumValue);
77-
}
73+
// //[Benchmark]
74+
// public string SmartEnum_Newtonsoft_Serialize()
75+
// {
76+
// return JsonConvert.SerializeObject(_smartEnumValue);
77+
// }
7878

79-
//[Benchmark]
80-
public ColorCode GenEnumValues_Newtonsoft_Deserialize()
81-
{
82-
return JsonConvert.DeserializeObject<ColorCode>("\"R\"")!;
83-
}
79+
// //[Benchmark]
80+
// public ColorCode GenEnumValues_Newtonsoft_Deserialize()
81+
// {
82+
// return JsonConvert.DeserializeObject<ColorCode>("\"R\"")!;
83+
// }
8484

85-
// [Benchmark]
86-
public ColorCodeIntellenum Intellenum_Newtonsoft_Deserialize()
87-
{
88-
return JsonConvert.DeserializeObject<ColorCodeIntellenum>("\"R\"")!;
89-
}
85+
// // [Benchmark]
86+
// public ColorCodeIntellenum Intellenum_Newtonsoft_Deserialize()
87+
// {
88+
// return JsonConvert.DeserializeObject<ColorCodeIntellenum>("\"R\"")!;
89+
// }
9090

91-
// [Benchmark]
92-
public ColorCodeSmartEnum SmartEnum_Newtonsoft_Deserialize()
93-
{
94-
return JsonConvert.DeserializeObject<ColorCodeSmartEnum>("\"R\"")!;
95-
}
91+
// // [Benchmark]
92+
// public ColorCodeSmartEnum SmartEnum_Newtonsoft_Deserialize()
93+
// {
94+
// return JsonConvert.DeserializeObject<ColorCodeSmartEnum>("\"R\"")!;
95+
// }
9696
}

test/Soenneker.Gen.EnumValues.Tests/Benchmarks/TryFromNameBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ public class TryFromNameBenchmark
2626
return (r, b);
2727
}
2828

29-
//[Benchmark]
29+
[Benchmark]
3030
public (ColorCodeSmartEnum?, ColorCodeSmartEnum?) SmartEnum()
3131
{
3232
ColorCodeSmartEnum.TryFromName(_red, out ColorCodeSmartEnum? r);
3333
ColorCodeSmartEnum.TryFromName(_blue, out ColorCodeSmartEnum? b);
3434
return (r, b);
3535
}
3636

37-
// [Benchmark]
37+
[Benchmark]
3838
public bool GenEnumValues_Miss()
3939
{
4040
return ColorCode.TryFromName(_miss, out _);
4141
}
4242

43-
// [Benchmark]
43+
[Benchmark]
4444
public bool Intellenum_Miss()
4545
{
4646
return ColorCodeIntellenum.TryFromName(_miss, out _);
4747
}
4848

49-
// [Benchmark]
49+
[Benchmark]
5050
public bool SmartEnum_Miss()
5151
{
5252
return ColorCodeSmartEnum.TryFromName(_miss, out _);

0 commit comments

Comments
 (0)