MCPcopy
hub / github.com/nats-io/nats.go / BenchmarkOldRequest

Function BenchmarkOldRequest

test/bench_test.go:153–175  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

151}
152
153func BenchmarkOldRequest(b *testing.B) {
154 b.StopTimer()
155 s := RunDefaultServer()
156 defer s.Shutdown()
157 nc, err := nats.Connect(nats.DefaultURL, nats.UseOldRequestStyle())
158 if err != nil {
159 b.Fatalf("Failed to connect: %v", err)
160 }
161 defer nc.Close()
162 ok := []byte("ok")
163 nc.Subscribe("req", func(m *nats.Msg) {
164 nc.Publish(m.Reply, ok)
165 })
166 b.StartTimer()
167 b.ReportAllocs()
168 q := []byte("q")
169 for i := 0; i < b.N; i++ {
170 _, err := nc.Request("req", q, 1*time.Second)
171 if err != nil {
172 b.Fatalf("Err %v\n", err)
173 }
174 }
175}
176
177func BenchmarkPublishValidation(b *testing.B) {
178 msgPayload := []byte("test")

Callers

nothing calls this directly

Calls 7

ConnectMethod · 0.80
FatalfMethod · 0.80
RunDefaultServerFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
RequestMethod · 0.45

Tested by

no test coverage detected