Skip to content

Commit 65b269f

Browse files
konradkonradjannikluhn
authored andcommitted
Suppress log and loop in bench
1 parent e33d203 commit 65b269f

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

rolling-shutter/keyper/epochkghandler/benchmark_test.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/jackc/pgx/v4/pgxpool"
99
pubsub "github.com/libp2p/go-libp2p-pubsub"
10+
"github.com/rs/zerolog"
1011
"gotest.tools/assert"
1112

1213
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
@@ -23,6 +24,7 @@ const numIdentityPreimages = 1000
2324

2425
func prepareBenchmark(ctx context.Context, b *testing.B, dbpool *pgxpool.Pool) (*testkeygen.EonKeys, []identitypreimage.IdentityPreimage) {
2526
b.Helper()
27+
zerolog.SetGlobalLevel(zerolog.Disabled)
2628
keyperIndex := uint64(1)
2729
identityPreimages := []identitypreimage.IdentityPreimage{}
2830
for i := 0; i < numIdentityPreimages; i++ {
@@ -38,6 +40,7 @@ func prepareBenchmark(ctx context.Context, b *testing.B, dbpool *pgxpool.Pool) (
3840

3941
func prepareKeysBenchmark(ctx context.Context, b *testing.B, dbpool *pgxpool.Pool) (p2p.MessageHandler, *p2pmsg.DecryptionKeys) {
4042
b.Helper()
43+
zerolog.SetGlobalLevel(zerolog.Disabled)
4144
keys, identityPreimages := prepareBenchmark(ctx, b, dbpool)
4245

4346
encodedDecryptionKeys := [][]byte{}
@@ -73,6 +76,7 @@ func prepareKeySharesBenchmark(
7376
isSecond bool,
7477
) (p2p.MessageHandler, *p2pmsg.DecryptionKeyShares) {
7578
b.Helper()
79+
zerolog.SetGlobalLevel(zerolog.Disabled)
7680
keys, identityPreimages := prepareBenchmark(ctx, b, dbpool)
7781
var handler p2p.MessageHandler = &DecryptionKeyShareHandler{config: config, dbpool: dbpool}
7882

@@ -125,10 +129,13 @@ func BenchmarkValidateKeysIntegration(b *testing.B) {
125129
handler, msg := prepareKeysBenchmark(ctx, b, dbpool)
126130

127131
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+
}
132139
}
133140

134141
func BenchmarkHandleKeysIntegration(b *testing.B) {
@@ -142,9 +149,12 @@ func BenchmarkHandleKeysIntegration(b *testing.B) {
142149
assert.Check(b, validationResult == pubsub.ValidationAccept)
143150

144151
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+
}
148158
}
149159

150160
func BenchmarkValidateFirstKeySharesIntegration(b *testing.B) {
@@ -154,10 +164,13 @@ func BenchmarkValidateFirstKeySharesIntegration(b *testing.B) {
154164
handler, msg := prepareKeySharesBenchmark(ctx, b, dbpool, false)
155165

156166
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+
}
161174
}
162175

163176
func BenchmarkHandleFirstKeySharesIntegration(b *testing.B) {
@@ -171,9 +184,12 @@ func BenchmarkHandleFirstKeySharesIntegration(b *testing.B) {
171184
assert.Check(b, validationResult == pubsub.ValidationAccept)
172185

173186
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+
}
177193
}
178194

179195
func BenchmarkValidateSecondKeySharesIntegration(b *testing.B) {
@@ -183,10 +199,13 @@ func BenchmarkValidateSecondKeySharesIntegration(b *testing.B) {
183199
handler, msg := prepareKeySharesBenchmark(ctx, b, dbpool, true)
184200

185201
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+
}
190209
}
191210

192211
func BenchmarkHandleSecondKeySharesIntegration(b *testing.B) {
@@ -200,7 +219,10 @@ func BenchmarkHandleSecondKeySharesIntegration(b *testing.B) {
200219
assert.Check(b, validationResult == pubsub.ValidationAccept)
201220

202221
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+
}
206228
}

0 commit comments

Comments
 (0)