-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
EqualsBenchmarks.cs
79 lines (56 loc) · 2.79 KB
/
EqualsBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
namespace Ardalis.SmartEnum.Benchmarks
{
using BenchmarkDotNet.Attributes;
using System.Diagnostics.CodeAnalysis;
[Config(typeof(Config))]
[SuppressMessage("Major Bug", "S1764:Identical expressions should not be used on both sides of operators", Justification = "<Pending>")]
public class EqualsBenchmarks
{
////////////////////////////////////////////////////////////////////////////////
// Enum
[Benchmark]
public int Enum_GetHashCode() => TestEnum.One.GetHashCode();
[Benchmark]
public bool Enum_Equals_SameValue() => TestEnum.One.Equals(TestEnum.One);
[Benchmark]
public bool Enum_Equals_DifferentValue() => TestEnum.One.Equals(TestEnum.Two);
[Benchmark]
public bool Enum_Equals_DifferentType() => TestEnum.One.Equals(TestEnum2.One);
[Benchmark]
public bool Enum_EqualOperator() => TestEnum.One == TestEnum.Two;
[Benchmark]
public bool Enum_NotEqualOperator() => TestEnum.One != TestEnum.Two;
////////////////////////////////////////////////////////////////////////////////
// Constant
[Benchmark]
public int Constant_GetHashCode() => TestConstant.One.GetHashCode();
[Benchmark]
public bool Constant_Equals_Null() => TestConstant.One.Equals((TestConstant)null);
[Benchmark]
public bool Constant_Equals_SameValue() => TestConstant.One.Equals(TestConstant.One);
[Benchmark]
public bool Constant_Equals_DifferentValue() => TestConstant.One.Equals(TestConstant.Two);
[Benchmark]
public bool Constant_Equals_DifferentType() => TestConstant.One.Equals(TestConstant2.One);
[Benchmark]
public bool Constant_EqualOperator() => TestConstant.One == TestConstant.Two;
[Benchmark]
public bool Constant_NotEqualOperator() => TestConstant.One != TestConstant.Two;
////////////////////////////////////////////////////////////////////////////////
// SmartEnum
[Benchmark]
public int SmartEnum_GetHashCode() => TestSmartEnum.One.GetHashCode();
[Benchmark]
public bool SmartEnum_Equals_Null() => TestSmartEnum.One.Equals((TestSmartEnum)null);
[Benchmark]
public bool SmartEnum_Equals_SameValue() => TestSmartEnum.One.Equals(TestSmartEnum.One);
[Benchmark]
public bool SmartEnum_Equals_DifferentValue() => TestSmartEnum.One.Equals(TestSmartEnum.Two);
[Benchmark]
public bool SmartEnum_Equals_DifferentType() => TestSmartEnum.One.Equals(TestSmartEnum2.One);
[Benchmark]
public bool SmartEnum_EqualOperator() => TestSmartEnum.One == TestSmartEnum.Two;
[Benchmark]
public bool SmartEnum_NotEqualOperator() => TestSmartEnum.One != TestSmartEnum.Two;
}
}