7
7
8
8
"github.com/jackc/pgx/v4/pgxpool"
9
9
pubsub "github.com/libp2p/go-libp2p-pubsub"
10
+ "github.com/rs/zerolog"
10
11
"gotest.tools/assert"
11
12
12
13
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
@@ -23,6 +24,7 @@ const numIdentityPreimages = 1000
23
24
24
25
func prepareBenchmark (ctx context.Context , b * testing.B , dbpool * pgxpool.Pool ) (* testkeygen.EonKeys , []identitypreimage.IdentityPreimage ) {
25
26
b .Helper ()
27
+ zerolog .SetGlobalLevel (zerolog .Disabled )
26
28
keyperIndex := uint64 (1 )
27
29
identityPreimages := []identitypreimage.IdentityPreimage {}
28
30
for i := 0 ; i < numIdentityPreimages ; i ++ {
@@ -38,6 +40,7 @@ func prepareBenchmark(ctx context.Context, b *testing.B, dbpool *pgxpool.Pool) (
38
40
39
41
func prepareKeysBenchmark (ctx context.Context , b * testing.B , dbpool * pgxpool.Pool ) (p2p.MessageHandler , * p2pmsg.DecryptionKeys ) {
40
42
b .Helper ()
43
+ zerolog .SetGlobalLevel (zerolog .Disabled )
41
44
keys , identityPreimages := prepareBenchmark (ctx , b , dbpool )
42
45
43
46
encodedDecryptionKeys := [][]byte {}
@@ -73,6 +76,7 @@ func prepareKeySharesBenchmark(
73
76
isSecond bool ,
74
77
) (p2p.MessageHandler , * p2pmsg.DecryptionKeyShares ) {
75
78
b .Helper ()
79
+ zerolog .SetGlobalLevel (zerolog .Disabled )
76
80
keys , identityPreimages := prepareBenchmark (ctx , b , dbpool )
77
81
var handler p2p.MessageHandler = & DecryptionKeyShareHandler {config : config , dbpool : dbpool }
78
82
@@ -125,10 +129,13 @@ func BenchmarkValidateKeysIntegration(b *testing.B) {
125
129
handler , msg := prepareKeysBenchmark (ctx , b , dbpool )
126
130
127
131
b .ResetTimer ()
128
- validationResult , err := handler .ValidateMessage (ctx , msg )
129
- b .StopTimer ()
130
- assert .NilError (b , err )
131
- assert .Check (b , validationResult == pubsub .ValidationAccept )
132
+ for i := 0 ; i < b .N ; i ++ {
133
+ b .StartTimer ()
134
+ validationResult , err := handler .ValidateMessage (ctx , msg )
135
+ b .StopTimer ()
136
+ assert .NilError (b , err )
137
+ assert .Check (b , validationResult == pubsub .ValidationAccept )
138
+ }
132
139
}
133
140
134
141
func BenchmarkHandleKeysIntegration (b * testing.B ) {
@@ -142,9 +149,12 @@ func BenchmarkHandleKeysIntegration(b *testing.B) {
142
149
assert .Check (b , validationResult == pubsub .ValidationAccept )
143
150
144
151
b .ResetTimer ()
145
- _ , err = handler .HandleMessage (ctx , msg )
146
- b .StopTimer ()
147
- assert .NilError (b , err )
152
+ for i := 0 ; i < b .N ; i ++ {
153
+ b .StartTimer ()
154
+ _ , err = handler .HandleMessage (ctx , msg )
155
+ b .StopTimer ()
156
+ assert .NilError (b , err )
157
+ }
148
158
}
149
159
150
160
func BenchmarkValidateFirstKeySharesIntegration (b * testing.B ) {
@@ -154,10 +164,13 @@ func BenchmarkValidateFirstKeySharesIntegration(b *testing.B) {
154
164
handler , msg := prepareKeySharesBenchmark (ctx , b , dbpool , false )
155
165
156
166
b .ResetTimer ()
157
- validationResult , err := handler .ValidateMessage (ctx , msg )
158
- b .StopTimer ()
159
- assert .NilError (b , err )
160
- assert .Check (b , validationResult == pubsub .ValidationAccept )
167
+ for i := 0 ; i < b .N ; i ++ {
168
+ b .StartTimer ()
169
+ validationResult , err := handler .ValidateMessage (ctx , msg )
170
+ b .StopTimer ()
171
+ assert .NilError (b , err )
172
+ assert .Check (b , validationResult == pubsub .ValidationAccept )
173
+ }
161
174
}
162
175
163
176
func BenchmarkHandleFirstKeySharesIntegration (b * testing.B ) {
@@ -171,9 +184,12 @@ func BenchmarkHandleFirstKeySharesIntegration(b *testing.B) {
171
184
assert .Check (b , validationResult == pubsub .ValidationAccept )
172
185
173
186
b .ResetTimer ()
174
- _ , err = handler .HandleMessage (ctx , msg )
175
- b .StopTimer ()
176
- assert .NilError (b , err )
187
+ for i := 0 ; i < b .N ; i ++ {
188
+ b .StartTimer ()
189
+ _ , err = handler .HandleMessage (ctx , msg )
190
+ b .StopTimer ()
191
+ assert .NilError (b , err )
192
+ }
177
193
}
178
194
179
195
func BenchmarkValidateSecondKeySharesIntegration (b * testing.B ) {
@@ -183,10 +199,13 @@ func BenchmarkValidateSecondKeySharesIntegration(b *testing.B) {
183
199
handler , msg := prepareKeySharesBenchmark (ctx , b , dbpool , true )
184
200
185
201
b .ResetTimer ()
186
- validationResult , err := handler .ValidateMessage (ctx , msg )
187
- b .StopTimer ()
188
- assert .NilError (b , err )
189
- assert .Check (b , validationResult == pubsub .ValidationAccept )
202
+ for i := 0 ; i < b .N ; i ++ {
203
+ b .StartTimer ()
204
+ validationResult , err := handler .ValidateMessage (ctx , msg )
205
+ b .StopTimer ()
206
+ assert .NilError (b , err )
207
+ assert .Check (b , validationResult == pubsub .ValidationAccept )
208
+ }
190
209
}
191
210
192
211
func BenchmarkHandleSecondKeySharesIntegration (b * testing.B ) {
@@ -200,7 +219,10 @@ func BenchmarkHandleSecondKeySharesIntegration(b *testing.B) {
200
219
assert .Check (b , validationResult == pubsub .ValidationAccept )
201
220
202
221
b .ResetTimer ()
203
- _ , err = handler .HandleMessage (ctx , msg )
204
- b .StopTimer ()
205
- assert .NilError (b , err )
222
+ for i := 0 ; i < b .N ; i ++ {
223
+ b .StartTimer ()
224
+ _ , err = handler .HandleMessage (ctx , msg )
225
+ b .StopTimer ()
226
+ assert .NilError (b , err )
227
+ }
206
228
}
0 commit comments