3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 16:09:32 +01:00

add a benchmark for NAMES

This commit is contained in:
Shivaram Lingamneni 2023-04-03 03:40:04 -04:00
parent a6664459f6
commit 3d5da0c39b

View File

@ -4,8 +4,10 @@
package irc package irc
import ( import (
"fmt"
"testing" "testing"
"github.com/ergochat/ergo/irc/languages"
"github.com/ergochat/ergo/irc/utils" "github.com/ergochat/ergo/irc/utils"
) )
@ -30,6 +32,47 @@ func BenchmarkGenerateBatchID(b *testing.B) {
} }
} }
func BenchmarkNames(b *testing.B) {
channelSize := 1024
server := &Server{
name: "ergo.test",
}
lm, err := languages.NewManager(false, "", "")
if err != nil {
b.Fatal(err)
}
server.config.Store(&Config{
languageManager: lm,
})
for i := 0; i < b.N; i++ {
channel := &Channel{
name: "#test",
nameCasefolded: "#test",
server: server,
members: make(MemberSet),
}
for j := 0; j < channelSize; j++ {
nick := fmt.Sprintf("client_%d", j)
client := &Client{
server: server,
nick: nick,
nickCasefolded: nick,
}
channel.members.Add(client)
channel.regenerateMembersCache()
session := &Session{
client: client,
}
rb := NewResponseBuffer(session)
channel.Names(client, rb)
if len(rb.messages) < 2 {
b.Fatalf("not enough messages: %d", len(rb.messages))
}
// to inspect the messages: line, _ := rb.messages[0].Line()
}
}
}
func TestUserMasks(t *testing.T) { func TestUserMasks(t *testing.T) {
var um UserMaskSet var um UserMaskSet