Skip to content

Instantly share code, notes, and snippets.

@hxzhouh
Created June 4, 2024 02:19
Show Gist options
  • Save hxzhouh/552a3cf5718836c54639b828b868bd02 to your computer and use it in GitHub Desktop.
Save hxzhouh/552a3cf5718836c54639b828b868bd02 to your computer and use it in GitHub Desktop.
compare unique
type testStruct2 struct {
c1 string
c2 string
c3 testStruct3
}
type testStruct3 struct {
c31 string
c32 string
}
type testStructData struct {
a int
b string
c testStruct2
}
func BenchmarkMake1(b *testing.B) {
c1 := testStructData{
a: 12,
b: "eee",
c: testStruct2{
c1: "aaa",
c2: "bbb",
c3: testStruct3{
c31: "ccc",
c32: "ddd",
},
},
}
for i := 0; i < b.N; i++ {
compareTestStructData(c1, c1)
}
}
func BenchmarkMake2(b *testing.B) {
c1 := testStructData{
a: 12,
b: "eee",
c: testStruct2{
c1: "aaa",
c2: "bbb",
c3: testStruct3{
c31: "ccc",
c32: "ddd",
},
},
}
u1 := Make(c1)
u2 := Make(c1)
for i := 0; i < b.N; i++ {
compareTestStructData1(u1, u2)
}
}
func compareTestStructData1(u1 Handle[testStructData], u2 Handle[testStructData]) bool {
return u1 == u2
}
func compareTestStructData(c1, c2 testStructData) bool {
return c1 == c2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment