@@ -905,6 +905,9 @@ var deepEqualTests = []DeepEqualTest{
905
905
{error (nil ), error (nil ), true },
906
906
{map [int ]string {1 : "one" , 2 : "two" }, map [int ]string {2 : "two" , 1 : "one" }, true },
907
907
{fn1 , fn2 , true },
908
+ {[]byte {1 , 2 , 3 }, []byte {1 , 2 , 3 }, true },
909
+ {[]MyByte {1 , 2 , 3 }, []MyByte {1 , 2 , 3 }, true },
910
+ {MyBytes {1 , 2 , 3 }, MyBytes {1 , 2 , 3 }, true },
908
911
909
912
// Inequalities
910
913
{1 , 2 , false },
@@ -950,6 +953,9 @@ var deepEqualTests = []DeepEqualTest{
950
953
{& [3 ]interface {}{1 , 2 , 4 }, & [3 ]interface {}{1 , 2 , "s" }, false },
951
954
{Basic {1 , 0.5 }, NotBasic {1 , 0.5 }, false },
952
955
{map [uint ]string {1 : "one" , 2 : "two" }, map [int ]string {2 : "two" , 1 : "one" }, false },
956
+ {[]byte {1 , 2 , 3 }, []MyByte {1 , 2 , 3 }, false },
957
+ {[]MyByte {1 , 2 , 3 }, MyBytes {1 , 2 , 3 }, false },
958
+ {[]byte {1 , 2 , 3 }, MyBytes {1 , 2 , 3 }, false },
953
959
954
960
// Possible loops.
955
961
{& loop1 , & loop1 , true },
@@ -1049,6 +1055,82 @@ func TestDeepEqualUnexportedMap(t *testing.T) {
1049
1055
}
1050
1056
}
1051
1057
1058
+ var deepEqualPerfTests = []struct {
1059
+ x , y interface {}
1060
+ }{
1061
+ {x : int8 (99 ), y : int8 (99 )},
1062
+ {x : []int8 {99 }, y : []int8 {99 }},
1063
+ {x : int16 (99 ), y : int16 (99 )},
1064
+ {x : []int16 {99 }, y : []int16 {99 }},
1065
+ {x : int32 (99 ), y : int32 (99 )},
1066
+ {x : []int32 {99 }, y : []int32 {99 }},
1067
+ {x : int64 (99 ), y : int64 (99 )},
1068
+ {x : []int64 {99 }, y : []int64 {99 }},
1069
+ {x : int (999999 ), y : int (999999 )},
1070
+ {x : []int {999999 }, y : []int {999999 }},
1071
+
1072
+ {x : uint8 (99 ), y : uint8 (99 )},
1073
+ {x : []uint8 {99 }, y : []uint8 {99 }},
1074
+ {x : uint16 (99 ), y : uint16 (99 )},
1075
+ {x : []uint16 {99 }, y : []uint16 {99 }},
1076
+ {x : uint32 (99 ), y : uint32 (99 )},
1077
+ {x : []uint32 {99 }, y : []uint32 {99 }},
1078
+ {x : uint64 (99 ), y : uint64 (99 )},
1079
+ {x : []uint64 {99 }, y : []uint64 {99 }},
1080
+ {x : uint (999999 ), y : uint (999999 )},
1081
+ {x : []uint {999999 }, y : []uint {999999 }},
1082
+ {x : uintptr (999999 ), y : uintptr (999999 )},
1083
+ {x : []uintptr {999999 }, y : []uintptr {999999 }},
1084
+
1085
+ {x : float32 (1.414 ), y : float32 (1.414 )},
1086
+ {x : []float32 {1.414 }, y : []float32 {1.414 }},
1087
+ {x : float64 (1.414 ), y : float64 (1.414 )},
1088
+ {x : []float64 {1.414 }, y : []float64 {1.414 }},
1089
+
1090
+ {x : complex64 (1.414 ), y : complex64 (1.414 )},
1091
+ {x : []complex64 {1.414 }, y : []complex64 {1.414 }},
1092
+ {x : complex128 (1.414 ), y : complex128 (1.414 )},
1093
+ {x : []complex128 {1.414 }, y : []complex128 {1.414 }},
1094
+
1095
+ {x : true , y : true },
1096
+ {x : []bool {true }, y : []bool {true }},
1097
+
1098
+ {x : "abcdef" , y : "abcdef" },
1099
+ {x : []string {"abcdef" }, y : []string {"abcdef" }},
1100
+
1101
+ {x : []byte ("abcdef" ), y : []byte ("abcdef" )},
1102
+ {x : [][]byte {[]byte ("abcdef" )}, y : [][]byte {[]byte ("abcdef" )}},
1103
+
1104
+ {x : [6 ]byte {'a' , 'b' , 'c' , 'a' , 'b' , 'c' }, y : [6 ]byte {'a' , 'b' , 'c' , 'a' , 'b' , 'c' }},
1105
+ {x : [][6 ]byte {[6 ]byte {'a' , 'b' , 'c' , 'a' , 'b' , 'c' }}, y : [][6 ]byte {[6 ]byte {'a' , 'b' , 'c' , 'a' , 'b' , 'c' }}},
1106
+ }
1107
+
1108
+ func TestDeepEqualAllocs (t * testing.T ) {
1109
+ for _ , tt := range deepEqualPerfTests {
1110
+ t .Run (ValueOf (tt .x ).Type ().String (), func (t * testing.T ) {
1111
+ got := testing .AllocsPerRun (100 , func () {
1112
+ if ! DeepEqual (tt .x , tt .y ) {
1113
+ t .Errorf ("DeepEqual(%v, %v)=false" , tt .x , tt .y )
1114
+ }
1115
+ })
1116
+ if int (got ) != 0 {
1117
+ t .Errorf ("DeepEqual(%v, %v) allocated %d times" , tt .x , tt .y , int (got ))
1118
+ }
1119
+ })
1120
+ }
1121
+ }
1122
+
1123
+ func BenchmarkDeepEqual (b * testing.B ) {
1124
+ for _ , bb := range deepEqualPerfTests {
1125
+ b .Run (ValueOf (bb .x ).Type ().String (), func (b * testing.B ) {
1126
+ b .ReportAllocs ()
1127
+ for i := 0 ; i < b .N ; i ++ {
1128
+ sink = DeepEqual (bb .x , bb .y )
1129
+ }
1130
+ })
1131
+ }
1132
+ }
1133
+
1052
1134
func check2ndField (x interface {}, offs uintptr , t * testing.T ) {
1053
1135
s := ValueOf (x )
1054
1136
f := s .Type ().Field (1 )
0 commit comments