Skip to content

Commit a23d530

Browse files
committed
Update
1 parent 94851a3 commit a23d530

File tree

9 files changed

+148
-29
lines changed

9 files changed

+148
-29
lines changed

src/.editorconfig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,12 +1451,24 @@ dotnet_diagnostic.S2360.severity = none
14511451
# Types and methods should not have too many generic parameters
14521452
dotnet_diagnostic.S2436.severity = none
14531453

1454+
# URI properties should not be strings
1455+
dotnet_diagnostic.S3996.severity = none
1456+
1457+
# Method signatures should not contain nested generic types
1458+
dotnet_diagnostic.S4017.severity = none
1459+
14541460
# Properties should be preferred, duplicate with CA1024
14551461
dotnet_diagnostic.S4049.severity = none
14561462

14571463
# Literals should not be passed as localized parameters
14581464
dotnet_diagnostic.S4055.severity = none
14591465

1466+
# Use UTC when recording DateTime instants
1467+
dotnet_diagnostic.S6563.severity = none
1468+
1469+
# Don't hardcode the format when turning dates and times to strings
1470+
dotnet_diagnostic.S6585.severity = none
1471+
14601472
# Controllers should not have mixed responsibilities
14611473
dotnet_diagnostic.S6960.severity = none
14621474

@@ -1565,6 +1577,9 @@ dotnet_diagnostic.S3400.severity = error
15651577
# S3459: Unassigned members should be removed
15661578
dotnet_diagnostic.S3459.severity = error
15671579

1580+
# Track use of "NotImplementedException"
1581+
dotnet_diagnostic.S3717.severity = error
1582+
15681583
# S3903: Types should be defined in named namespaces
15691584
dotnet_diagnostic.S3903.severity = error
15701585

@@ -1623,7 +1638,7 @@ resharper_outdent_statement_labels = true
16231638
##########################################
16241639

16251640
# Consider making public types internal
1626-
dotnet_diagnostic.CA1515.severity = suggestion
1641+
dotnet_diagnostic.CA1515.severity = none
16271642

16281643
# Avoid unused private fields
16291644
dotnet_diagnostic.CA1823.severity = none
@@ -1635,6 +1650,9 @@ dotnet_diagnostic.CA2007.severity = none
16351650
# Unused local variables should be removed
16361651
dotnet_diagnostic.S1481.severity = none
16371652

1653+
# Operator overloads have named alternates
1654+
dotnet_diagnostic.CA2225.severity = none
1655+
16381656
# duplicate with CA2213
16391657
# Classes should "Dispose" of members from the classes' own "Dispose" methods
16401658
dotnet_diagnostic.S2952.severity = none
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```
2+
3+
BenchmarkDotNet v0.15.2, Windows 10 (10.0.19045.5487/22H2/2022Update)
4+
Intel Xeon CPU E5-2667 v4 3.20GHz, 1 CPU, 16 logical and 8 physical cores
5+
.NET SDK 9.0.304
6+
[Host] : .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2
7+
MediumRun : .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2
8+
9+
Job=MediumRun IterationCount=15 LaunchCount=1
10+
WarmupCount=10
11+
12+
```
13+
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Allocated | Alloc Ratio |
14+
|--------------------------------- |----------:|----------:|----------:|----------:|------:|--------:|----------:|------------:|
15+
| DerivedClass_Property | 0.3260 ns | 0.0403 ns | 0.0377 ns | 0.3120 ns | ? | ? | - | ? |
16+
| ExtendedClass_AdditionalProperty | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.0000 ns | ? | ? | - | ? |
17+
| ExtendedClass_StandardProperty | 0.0051 ns | 0.0059 ns | 0.0056 ns | 0.0017 ns | ? | ? | - | ? |
18+
| SealedClass_Property | 0.0117 ns | 0.0142 ns | 0.0126 ns | 0.0081 ns | ? | ? | - | ? |
19+
| StandardClass_Property | 0.0070 ns | 0.0096 ns | 0.0085 ns | 0.0038 ns | ? | ? | - | ? |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Median,Ratio,RatioSD,Allocated,Alloc Ratio
2+
DerivedClass_Property,MediumRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 9.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,15,Default,1,Default,Default,Default,Default,Default,Default,16,10,0.3260 ns,0.0403 ns,0.0377 ns,0.3120 ns,?,?,0 B,?
3+
ExtendedClass_AdditionalProperty,MediumRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 9.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,15,Default,1,Default,Default,Default,Default,Default,Default,16,10,0.0000 ns,0.0000 ns,0.0000 ns,0.0000 ns,?,?,0 B,?
4+
ExtendedClass_StandardProperty,MediumRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 9.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,15,Default,1,Default,Default,Default,Default,Default,Default,16,10,0.0051 ns,0.0059 ns,0.0056 ns,0.0017 ns,?,?,0 B,?
5+
SealedClass_Property,MediumRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 9.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,15,Default,1,Default,Default,Default,Default,Default,Default,16,10,0.0117 ns,0.0142 ns,0.0126 ns,0.0081 ns,?,?,0 B,?
6+
StandardClass_Property,MediumRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 9.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,15,Default,1,Default,Default,Default,Default,Default,Default,16,10,0.0070 ns,0.0096 ns,0.0085 ns,0.0038 ns,?,?,0 B,?
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang='en'>
3+
<head>
4+
<meta charset='utf-8' />
5+
<title>StructTest.ClassBenchmark-20251112-164936</title>
6+
7+
<style type="text/css">
8+
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
9+
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
10+
tr { background-color: #fff; border-top: 1px solid #ccc; }
11+
tr:nth-child(even) { background: #f8f8f8; }
12+
</style>
13+
</head>
14+
<body>
15+
<pre><code>
16+
BenchmarkDotNet v0.15.2, Windows 10 (10.0.19045.5487/22H2/2022Update)
17+
Intel Xeon CPU E5-2667 v4 3.20GHz, 1 CPU, 16 logical and 8 physical cores
18+
.NET SDK 9.0.304
19+
[Host] : .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2
20+
MediumRun : .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2
21+
</code></pre>
22+
<pre><code>Job=MediumRun IterationCount=15 LaunchCount=1
23+
WarmupCount=10
24+
</code></pre>
25+
26+
<table>
27+
<thead><tr><th>Method </th><th>Mean</th><th>Error</th><th>StdDev</th><th>Median</th><th>Ratio</th><th>RatioSD</th><th>Allocated</th><th>Alloc Ratio</th>
28+
</tr>
29+
</thead><tbody><tr><td>DerivedClass_Property</td><td>0.3260 ns</td><td>0.0403 ns</td><td>0.0377 ns</td><td>0.3120 ns</td><td>?</td><td>?</td><td>-</td><td>?</td>
30+
</tr><tr><td>ExtendedClass_AdditionalProperty</td><td>0.0000 ns</td><td>0.0000 ns</td><td>0.0000 ns</td><td>0.0000 ns</td><td>?</td><td>?</td><td>-</td><td>?</td>
31+
</tr><tr><td>ExtendedClass_StandardProperty</td><td>0.0051 ns</td><td>0.0059 ns</td><td>0.0056 ns</td><td>0.0017 ns</td><td>?</td><td>?</td><td>-</td><td>?</td>
32+
</tr><tr><td>SealedClass_Property</td><td>0.0117 ns</td><td>0.0142 ns</td><td>0.0126 ns</td><td>0.0081 ns</td><td>?</td><td>?</td><td>-</td><td>?</td>
33+
</tr><tr><td>StandardClass_Property</td><td>0.0070 ns</td><td>0.0096 ns</td><td>0.0085 ns</td><td>0.0038 ns</td><td>?</td><td>?</td><td>-</td><td>?</td>
34+
</tr></tbody></table>
35+
</body>
36+
</html>

src/Tests/StructTest/ClassBenchmark.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ public int GetAdditionalProperty()
100100
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
101101
public class ClassBenchmark
102102
{
103+
104+
#region Constants & Statics
105+
106+
private const int Count = 1_000_000;
107+
108+
#endregion
109+
103110
private readonly DerivedClass _derivedClassInstance = new() { DerivedProperty = 42 };
104111
private readonly ExtendedStandardClass _extendedClassInstance = new()
105112
{
@@ -114,30 +121,55 @@ public class ClassBenchmark
114121
[Benchmark]
115122
public int DerivedClass_Property()
116123
{
124+
//for (var i = 0; i < Count; i++)
125+
//{
126+
// _derivedClassInstance.GetBaseProperty();
127+
//}
128+
117129
return _derivedClassInstance.GetBaseProperty();
118130
}
119131

120132
[Benchmark]
121133
public int ExtendedClass_AdditionalProperty()
122134
{
135+
//for (var i = 0; i < Count; i++)
136+
//{
137+
// _extendedClassInstance.GetAdditionalProperty();
138+
//}
139+
123140
return _extendedClassInstance.GetAdditionalProperty();
124141
}
125142

126143
[Benchmark]
127144
public int ExtendedClass_StandardProperty()
128145
{
146+
//for (var i = 0; i < Count; i++)
147+
//{
148+
// _extendedClassInstance.GetStandardProperty();
149+
//}
150+
129151
return _extendedClassInstance.GetStandardProperty();
130152
}
131153

132154
[Benchmark]
133155
public int SealedClass_Property()
134156
{
157+
//for (var i = 0; i < Count; i++)
158+
//{
159+
// _sealedClassInstance.GetSealedProperty();
160+
//}
161+
135162
return _sealedClassInstance.GetSealedProperty();
136163
}
137164

138165
[Benchmark(Baseline = true)]
139166
public int StandardClass_Property()
140167
{
168+
//for (var i = 0; i < Count; i++)
169+
//{
170+
// _standardClassInstance.GetStandardProperty();
171+
//}
172+
141173
return _standardClassInstance.GetStandardProperty();
142174
}
143175

src/Tests/StructTest/Program.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
using BenchmarkDotNet.Running;
2-
31
namespace StructTest;
42

5-
internal sealed class Program
3+
internal static class Program
64
{
75

86
#region Constants & Statics
97

108
private static void Main(string[] args)
119
{
12-
//var m1 = new Measurement();
13-
//Console.WriteLine(m1); // output: NaN (Undefined)
10+
var m1 = new Measurement();
11+
Console.WriteLine(m1); // output: NaN (Undefined)
12+
13+
var m2 = default(Measurement);
14+
Console.WriteLine(m2); // output: 0 ()
1415

15-
//var m2 = default(Measurement);
16-
//Console.WriteLine(m2); // output: 0 ()
16+
var ms = new Measurement[2];
17+
Console.WriteLine(string.Join(", ", ms)); // output: 0 (), 0 ()
1718

18-
//var ms = new Measurement[2];
19-
//Console.WriteLine(string.Join(", ", ms)); // output: 0 (), 0 ()
19+
ValueTypeTest.ShowSize();
2020

21-
//ValueTypeTest.ShowSize();
21+
ValueTypeTest.OutOfPrecision_True_Test();
22+
ValueTypeTest.OutOfPrecision_False_Test();
2223

23-
//ValueTypeTest.OutOfPrecisionTrueTest();
24-
//ValueTypeTest.OutOfPrecisionFalseTest();
24+
Console.WriteLine();
25+
ValueTypeTest.EffectiveLength_4();
2526

26-
//Console.WriteLine();
27-
//ValueTypeTest.EffectiveLength_4();
27+
Console.WriteLine();
28+
ValueTypeTest.RoundAlgorithm();
2829

29-
//Console.WriteLine();
30-
//ValueTypeTest.RoundAlgorithm();
30+
ValidationTest.ValidationError();
31+
Console.WriteLine();
32+
ValidationTest.ValidationAllow();
3133

32-
//ValidationTest.ValidationError();
33-
//Console.WriteLine();
34-
//ValidationTest.ValidationAllow();
34+
//var config = DefaultConfig.Instance
35+
// .WithArtifactsPath(
36+
// $".\\BenchmarkDotNet.Aritfacts.{DateTime.Now.ToString("u").Replace(' ', '_').Replace(':', '-')}")
37+
// .AddExporter(MarkdownExporter.GitHub)
38+
// .AddDiagnoser(MemoryDiagnoser.Default)
39+
// .AddJob(Job.MediumRun.WithLaunchCount(1));
3540

36-
_ = BenchmarkRunner.Run<ClassBenchmark>();
41+
//_ = BenchmarkRunner.Run<ClassBenchmark>(config);
3742
}
3843

3944
#endregion
4045

41-
protected Program()
42-
{
43-
}
4446
}

src/Tests/StructTest/ValidationTest.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public static void ValidationAllow()
1313
{
1414
Price = 100_000.00m,
1515
Price2 = 0.01m,
16-
Price3 = 1000000000000000, // no error, is wrong!
16+
Price3 = 1_000_000_000_000_000, // no error, is wrong!
17+
Price33 = 1_000_000_000_000_000, // no error, is wrong!
1718
Price4 = 999_999_999_999_999.99981m // no error
1819
};
1920
var context = new ValidationContext(product);
@@ -37,6 +38,7 @@ public static void ValidationError()
3738
Price = -1.00m,
3839
Price2 = 0.001m,
3940
Price3 = 999_999_999_999_999.99991m, // no error, is wrong!
41+
Price33 = 999_999_999_999_999.99991, // no error, is wrong!
4042
Price4 = 999_999_999_999_999.99991m // error
4143
};
4244
var context = new ValidationContext(product);
@@ -68,10 +70,13 @@ public class Product
6870
[DisplayFormat(DataFormatString = "{0:C2}")]
6971
public decimal Price2 { get; set; }
7072

71-
[Range(0.0001, 999_999_999_999_999.9999)] // 超过 double 有效位数,between 0.0001 and 1000000000000000
73+
[Range(0.0001, 999_999_999_999_999.9999)] // Range参数只有double,所以不能超过 double 有效位数,between 0.0001 and 1000000000000000
7274
public decimal Price3 { get; set; }
7375

74-
[Range(typeof(decimal), "0.0001", "999999999999999.9999")]
76+
[Range(typeof(double), 0.0001, 999_999_999_999_999.9999)] //
77+
public double Price33 { get; set; }
78+
79+
[Range(typeof(decimal), "0.0001", "999999999999999.9999")] // decimal Range条件需要使用string参数,避免double精度问题
7580
public decimal Price4 { get; set; }
7681

7782
#endregion

src/Tests/StructTest/ValueTypeTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void EffectiveLength_4()
2626
Console.WriteLine($"decimal 18+4 {ff}");
2727
}
2828

29-
public static void OutOfPrecisionFalseTest()
29+
public static void OutOfPrecision_False_Test()
3030
{
3131
//(15 - 16 位有效数字)
3232
var maxValue = 999_999_999_999.9999; // 12 位整数部分 + 4 位小数
@@ -37,7 +37,7 @@ public static void OutOfPrecisionFalseTest()
3737
Console.WriteLine($"Are maxValue and beyondMax equal? {maxValue == beyondMax}");
3838
}
3939

40-
public static void OutOfPrecisionTrueTest()
40+
public static void OutOfPrecision_True_Test()
4141
{
4242
//(15 - 16 位有效数字)
4343
var maxValue = 1_999_999_999_999.9999; // 超过 12 位整数部分 + 4 位小数

src/Tests/StructTest/run_test.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet run -c Release

0 commit comments

Comments
 (0)