Пример #1
0
//Test function to make sure that everything is working before benching
func TestEcho(t *testing.T) {
	var ping Message
	ping.InitFromBytes('i', []byte("ftest"))
	var pong Message

	buf := buf.NewPackBuffer(1024)

	ms := NewBackendStream(buf)
	ms.Send(&ping)
	t.Logf("%v", buf)

	ms.Next(&pong)

	rest, _ := pong.Force()
	t.Logf("Type:%v, bytes:%v,", pong.MsgType(), rest)
}
Пример #2
0
//Benchmark for testing how long the send operation on a MessageStream takes
func BenchmarkEchoSend(b *testing.B) {
	b.StopTimer()
	var ping Message
	var pong Message

	ping.InitFromBytes('i', make([]byte, 50))
	buf := buf.NewPackBuffer(2048)
	ms := NewBackendStream(buf)

	for i := 0; i < b.N; i++ {
		b.StartTimer()
		for j := 0; j < 1000; j++ {
			ms.Send(&ping)
		}
		b.StopTimer()
		for j := 0; j < 1000; j++ {
			ms.Next(&pong)
		}
	}
}