Skip to content

Commit

Permalink
chore: add a benchmark for SubscriberList (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Sep 2, 2022
1 parent c22e86e commit b157ff6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions subscriber_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package mercure

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)

func BenchmarkSubscriberList(b *testing.B) {
logger := zap.NewNop()

l := NewSubscriberList(100)
for i := 0; i < 100; i++ {
s := NewSubscriber("", logger)
t := fmt.Sprintf("https://example.com/%d", (i % 10))
s.SetTopics([]string{"https://example.org/foo", t}, []string{"https://example.net/bar", t})

l.Add(s)
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
assert.NotEmpty(b, l.MatchAny(&Update{Topics: []string{"https://example.org/foo"}}))
assert.Empty(b, l.MatchAny(&Update{Topics: []string{"https://example.org/baz"}}))
assert.NotEmpty(b, l.MatchAny(&Update{Topics: []string{"https://example.com/8"}, Private: false}))
}
}

0 comments on commit b157ff6

Please sign in to comment.