...
1
2
3
4
5 package reflectdata_test
6
7 import (
8 "testing"
9 )
10
11 func BenchmarkEqArrayOfStrings5(b *testing.B) {
12 var a [5]string
13 var c [5]string
14
15 for i := 0; i < 5; i++ {
16 a[i] = "aaaa"
17 c[i] = "cccc"
18 }
19
20 for j := 0; j < b.N; j++ {
21 _ = a == c
22 }
23 }
24
25 func BenchmarkEqArrayOfStrings64(b *testing.B) {
26 var a [64]string
27 var c [64]string
28
29 for i := 0; i < 64; i++ {
30 a[i] = "aaaa"
31 c[i] = "cccc"
32 }
33
34 for j := 0; j < b.N; j++ {
35 _ = a == c
36 }
37 }
38
39 func BenchmarkEqArrayOfStrings1024(b *testing.B) {
40 var a [1024]string
41 var c [1024]string
42
43 for i := 0; i < 1024; i++ {
44 a[i] = "aaaa"
45 c[i] = "cccc"
46 }
47
48 for j := 0; j < b.N; j++ {
49 _ = a == c
50 }
51 }
52
53 func BenchmarkEqArrayOfFloats5(b *testing.B) {
54 var a [5]float32
55 var c [5]float32
56
57 for i := 0; i < b.N; i++ {
58 _ = a == c
59 }
60 }
61
62 func BenchmarkEqArrayOfFloats64(b *testing.B) {
63 var a [64]float32
64 var c [64]float32
65
66 for i := 0; i < b.N; i++ {
67 _ = a == c
68 }
69 }
70
71 func BenchmarkEqArrayOfFloats1024(b *testing.B) {
72 var a [1024]float32
73 var c [1024]float32
74
75 for i := 0; i < b.N; i++ {
76 _ = a == c
77 }
78 }
79
80 func BenchmarkEqArrayOfStructsEq(b *testing.B) {
81 type T2 struct {
82 a string
83 b int
84 }
85 const size = 1024
86 var (
87 str1 = "foobar"
88
89 a [size]T2
90 c [size]T2
91 )
92
93 for i := 0; i < size; i++ {
94 a[i].a = str1
95 c[i].a = str1
96 }
97
98 b.ResetTimer()
99 for j := 0; j < b.N; j++ {
100 _ = a == c
101 }
102 }
103
104 func BenchmarkEqArrayOfStructsNotEq(b *testing.B) {
105 type T2 struct {
106 a string
107 b int
108 }
109 const size = 1024
110 var (
111 str1 = "foobar"
112 str2 = "foobarz"
113
114 a [size]T2
115 c [size]T2
116 )
117
118 for i := 0; i < size; i++ {
119 a[i].a = str1
120 c[i].a = str1
121 }
122 c[len(c)-1].a = str2
123
124 b.ResetTimer()
125 for j := 0; j < b.N; j++ {
126 _ = a == c
127 }
128 }
129
130 const size = 16
131
132 type T1 struct {
133 a [size]byte
134 }
135
136 func BenchmarkEqStruct(b *testing.B) {
137 x, y := T1{}, T1{}
138 x.a = [size]byte{1, 2, 3, 4, 5, 6, 7, 8}
139 y.a = [size]byte{2, 3, 4, 5, 6, 7, 8, 9}
140
141 for i := 0; i < b.N; i++ {
142 f := x == y
143 if f {
144 println("hello")
145 }
146 }
147 }
148
View as plain text