Codebase list golang-github-go-kit-kit / 756104ab-e3ba-487b-8d5b-cc84465cfc29/main sd / benchmark_test.go
756104ab-e3ba-487b-8d5b-cc84465cfc29/main

Tree @756104ab-e3ba-487b-8d5b-cc84465cfc29/main (Download .tar.gz)

benchmark_test.go @756104ab-e3ba-487b-8d5b-cc84465cfc29/main

c80303e
9a19822
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c80303e
9a19822
 
 
 
c80303e
9a19822
 
 
 
 
 
 
package sd

import (
	"io"
	"testing"

	"github.com/go-kit/kit/endpoint"
	"github.com/go-kit/kit/log"
)

func BenchmarkEndpoints(b *testing.B) {
	var (
		ca      = make(closer)
		cb      = make(closer)
		cmap    = map[string]io.Closer{"a": ca, "b": cb}
		factory = func(instance string) (endpoint.Endpoint, io.Closer, error) { return endpoint.Nop, cmap[instance], nil }
		c       = newEndpointCache(factory, log.NewNopLogger(), endpointerOptions{})
	)

	b.ReportAllocs()

	c.Update(Event{Instances: []string{"a", "b"}})

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			c.Endpoints()
		}
	})
}