@@ -11,40 +11,53 @@ namespace System.Reflection.Metadata
11
11
[ BenchmarkCategory ( Categories . Libraries ) ]
12
12
public class Perf_TypeName
13
13
{
14
+ public class ArgumentTypeWrapper
15
+ {
16
+ private readonly string displayName ;
17
+
18
+ public ArgumentTypeWrapper ( Type type , string displayName )
19
+ {
20
+ Type = type ;
21
+ this . displayName = displayName ;
22
+ }
23
+
24
+ public Type Type { get ; }
25
+ public override string ToString ( ) => displayName ;
26
+ }
27
+
14
28
public IEnumerable < object > TypeArguments ( )
15
29
{
16
- // We don't return strings here, as they change over the time when assembly versions get increased.
17
- // This would change benchmark ID and loose historical data tracking.
18
- yield return typeof ( int ) ; // elemental type
19
- yield return typeof ( int ) . MakePointerType ( ) ; // a pointer to an elemental type
20
- yield return typeof ( int ) . MakeByRefType ( ) ; // a reference to an elemental type
21
- yield return typeof ( int [ ] ) ; // SZArray
22
- yield return typeof ( int ) . MakeArrayType ( 1 ) ; // single-dimensional array, but not indexed from 0
23
- yield return typeof ( int ) . MakeArrayType ( 2 ) ; // multi-dimensional array
24
- yield return typeof ( Dictionary < string , bool > ) ; // generic type
25
- yield return typeof ( Dictionary < string , bool > [ ] ) ; // an array of generic types
26
- yield return typeof ( Nested ) ; // nested type
27
- yield return typeof ( Nested . NestedGeneric < string , bool > ) ; // nested generic type
28
- yield return typeof ( Dictionary < List < int [ ] > [ , ] , List < int ? [ ] [ ] [ , ] > > [ ] ) ; // complex generic type (node count = 16)
30
+ // We use a wrapper type for each argument to ensure that the test name remains the same into the future
31
+ yield return new ArgumentTypeWrapper ( typeof ( int ) , "typeof(int)" ) ; // elemental type
32
+ yield return new ArgumentTypeWrapper ( typeof ( int ) . MakePointerType ( ) , "typeof(System.Int32*)" ) ; // a pointer to an elemental type
33
+ yield return new ArgumentTypeWrapper ( typeof ( int ) . MakeByRefType ( ) , "typeof(System.Int32&)" ) ; // a reference to an elemental type
34
+ yield return new ArgumentTypeWrapper ( typeof ( int [ ] ) , "typeof(System.Int32[])" ) ; // SZArray
35
+ yield return new ArgumentTypeWrapper ( typeof ( int ) . MakeArrayType ( 1 ) , "typeof(System.Int32[*])" ) ; // single-dimensional array, but not indexed from 0
36
+ yield return new ArgumentTypeWrapper ( typeof ( int ) . MakeArrayType ( 2 ) , "typeof(System.Int32[,])" ) ; // multi-dimensional array
37
+ yield return new ArgumentTypeWrapper ( typeof ( Dictionary < string , bool > ) , "typeof(System.Collections.Generic.Dictionary<String, Boolean>)" ) ; // generic type
38
+ yield return new ArgumentTypeWrapper ( typeof ( Dictionary < string , bool > [ ] ) , "typeof(System.Collections.Generic.Dictionary`2[])" ) ; // an array of generic types
39
+ yield return new ArgumentTypeWrapper ( typeof ( Nested ) , "typeof(System.Reflection.Metadata.Nested)" ) ; // nested type
40
+ yield return new ArgumentTypeWrapper ( typeof ( Nested . NestedGeneric < string , bool > ) , "typeof(System.Reflection.Metadata.NestedGeneric<String, Boolean>)" ) ; // nested generic type
41
+ yield return new ArgumentTypeWrapper ( typeof ( Dictionary < List < int [ ] > [ , ] , List < int ? [ ] [ ] [ , ] > > [ ] ) , "typeof(System.Collections.Generic.Dictionary`2[]) (COMPLEX)" ) ; // complex generic type (node count = 16)
29
42
}
30
43
31
44
[ Benchmark ]
32
45
[ ArgumentsSource ( nameof ( TypeArguments ) ) ]
33
- public TypeName Parse_FullNames ( Type input ) => TypeName . Parse ( input . FullName ) ;
46
+ public TypeName Parse_FullNames ( ArgumentTypeWrapper input ) => TypeName . Parse ( input . Type . FullName ) ;
34
47
35
48
[ Benchmark ]
36
49
[ ArgumentsSource ( nameof ( TypeArguments ) ) ]
37
- public TypeName Parse_AssemblyQualifiedName ( Type input ) => TypeName . Parse ( input . AssemblyQualifiedName ) ;
50
+ public TypeName Parse_AssemblyQualifiedName ( ArgumentTypeWrapper input ) => TypeName . Parse ( input . Type . AssemblyQualifiedName ) ;
38
51
39
52
// The Name, FullName and AssemblyQualifiedName properties are lazy and cached,
40
- // so we need to parse a new TypName instance in order to get these properties calculated.
53
+ // so we need to parse a new TypeName instance in order to get these properties calculated.
41
54
[ Benchmark ]
42
55
[ ArgumentsSource ( nameof ( TypeArguments ) ) ]
43
- public string ParseAndGetFullName ( Type input ) => TypeName . Parse ( input . FullName ) . FullName ;
56
+ public string ParseAndGetFullName ( ArgumentTypeWrapper input ) => TypeName . Parse ( input . Type . FullName ) . FullName ;
44
57
45
58
[ Benchmark ]
46
59
[ ArgumentsSource ( nameof ( TypeArguments ) ) ]
47
- public string ParseAndGetAssemblyQualifiedName ( Type input ) => TypeName . Parse ( input . AssemblyQualifiedName ) . AssemblyQualifiedName ;
60
+ public string ParseAndGetAssemblyQualifiedName ( ArgumentTypeWrapper input ) => TypeName . Parse ( input . Type . AssemblyQualifiedName ) . AssemblyQualifiedName ;
48
61
49
62
public IEnumerable < string > InvalidArguments ( )
50
63
{
0 commit comments