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

Function BenchmarkPublishSpeedViaChan

test/netchan_test.go:334–365  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

332}
333
334func BenchmarkPublishSpeedViaChan(b *testing.B) {
335 b.StopTimer()
336
337 s := RunDefaultServer()
338 defer s.Shutdown()
339
340 nc, err := nats.Connect(nats.DefaultURL)
341 if err != nil {
342 b.Fatalf("Could not connect: %v\n", err)
343 }
344 ec, err := nats.NewEncodedConn(nc, nats.DEFAULT_ENCODER)
345 if err != nil {
346 b.Fatalf("Failed creating encoded connection: %v\n", err)
347 }
348 defer ec.Close()
349
350 ch := make(chan int32, 1024)
351 if err := ec.BindSendChan("foo", ch); err != nil {
352 b.Fatalf("Failed to bind to a send channel: %v\n", err)
353 }
354
355 b.StartTimer()
356
357 num := int32(22)
358
359 for i := 0; i < b.N; i++ {
360 ch <- num
361 }
362 // Make sure they are all processed.
363 nc.Flush()
364 b.StopTimer()
365}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
BindSendChanMethod · 0.95
ConnectMethod · 0.80
FatalfMethod · 0.80
RunDefaultServerFunction · 0.70
FlushMethod · 0.45

Tested by

no test coverage detected