sliding-sync/sync3/lists_test.go

52 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-02-02 15:00:34 +00:00
package sync3_test
import (
"context"
2023-02-02 15:00:34 +00:00
"fmt"
"sync/atomic"
"testing"
"time"
"github.com/matrix-org/sliding-sync/internal"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/sync3/caches"
)
var roomCounter atomic.Int64
var timestamp = time.Now()
func BenchmarkSortRooms(b *testing.B) {
for i := 0; i < b.N; i++ {
sortRooms(4000)
}
}
func sortRooms(n int) {
list := sync3.NewInternalRequestLists()
addRooms(list, n)
list.AssignList(context.Background(), "benchmark", &sync3.RequestFilters{}, []string{sync3.SortByRecency}, sync3.Overwrite)
2023-02-02 15:00:34 +00:00
}
func addRooms(list *sync3.InternalRequestLists, n int) {
for i := 0; i < n; i++ {
next := roomCounter.Add(1)
2023-05-23 16:14:06 +01:00
messageTimestamp := uint64(timestamp.Add(time.Duration(next) * time.Minute).UnixMilli())
lastInterestedEventTimestamps := make(map[string]uint64)
for _, listKey := range list.ListKeys() {
lastInterestedEventTimestamps[listKey] = messageTimestamp
}
2023-02-02 15:00:34 +00:00
list.SetRoom(sync3.RoomConnMetadata{
RoomMetadata: internal.RoomMetadata{
RoomID: fmt.Sprintf("!%d:benchmark", next),
JoinCount: int(next % 100),
NameEvent: fmt.Sprintf("Room %d", next),
2023-05-23 16:14:06 +01:00
LastMessageTimestamp: messageTimestamp,
2023-02-02 15:00:34 +00:00
},
UserRoomData: caches.UserRoomData{
IsDM: next%10 == 0,
},
LastInterestedEventTimestamps: lastInterestedEventTimestamps,
2023-05-24 15:50:53 +01:00
})
2023-02-02 15:00:34 +00:00
}
}