(b *testing.B)
| 332 | } |
| 333 | |
| 334 | func 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 | } |
nothing calls this directly
no test coverage detected