github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/cluster/rendezvous_test.go (about)

     1  package cluster
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"testing"
     7  )
     8  
     9  func Benchmark_Rendezvous_Get(b *testing.B) {
    10  
    11  	for _, v := range []int{1, 2, 3, 5, 10, 100, 1000, 2000} {
    12  		members := newMembersForTest(v)
    13  		ms := newDefaultMemberStrategy(nil, "kind").(*simpleMemberStrategy)
    14  		for _, member := range members {
    15  			ms.AddMember(member)
    16  		}
    17  		obj := NewRendezvous()
    18  		obj.UpdateMembers(members)
    19  		testName := fmt.Sprintf("member*%d", v)
    20  		runtime.GC()
    21  		b.Run(testName, func(b *testing.B) {
    22  			for i := 0; i < b.N; i++ {
    23  				address := obj.GetByIdentity("kind/0123456789abcdefghijklmnopqrstuvwxyz")
    24  				if address == "" {
    25  					b.Fatalf("empty address res=%d", len(members))
    26  				}
    27  			}
    28  		})
    29  	}
    30  }