| 297 | } |
| 298 | |
| 299 | func BenchmarkSendMessage(b *testing.B) { |
| 300 | q := New("channel") |
| 301 | //mempool |
| 302 | b.ReportAllocs() |
| 303 | go func() { |
| 304 | client := q.Client() |
| 305 | client.Sub("mempool") |
| 306 | defer client.Close() |
| 307 | for msg := range client.Recv() { |
| 308 | go func(msg *Message) { |
| 309 | if msg.Ty == types.EventTx { |
| 310 | msg.Reply(client.NewMessage("mempool", types.EventReply, types.Reply{IsOk: true, Msg: []byte("word")})) |
| 311 | } |
| 312 | }(msg) |
| 313 | } |
| 314 | }() |
| 315 | go q.Start() |
| 316 | client := q.Client() |
| 317 | //high 优先级 |
| 318 | msg := client.NewMessage("mempool", types.EventTx, "hello") |
| 319 | for i := 0; i < b.N; i++ { |
| 320 | err := client.Send(msg, true) |
| 321 | if err != nil { |
| 322 | b.Error(err) |
| 323 | return |
| 324 | } |
| 325 | _, err = client.Wait(msg) |
| 326 | if err != nil { |
| 327 | b.Error(err) |
| 328 | return |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | func BenchmarkStructChan(b *testing.B) { |
| 334 | ch := make(chan struct{}) |