diff --git a/benchmark_test.go b/benchmark_test.go index 070df6c..5c09cac 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -2,6 +2,7 @@ package bidirpc import ( "net" + "net/rpc" "testing" ) @@ -36,14 +37,23 @@ func (s *BenchService) EchoString(args StringArgs, reply *StringReply) error { var ( sessionYin *Session sessionYang *Session + client *rpc.Client + server *rpc.Server ) func init() { + service := &BenchService{} + connYin, connYang := net.Pipe() sessionYin, _ = NewSession(connYin, true) sessionYang, _ = NewSession(connYang, false) - service := &BenchService{} sessionYin.Register(service) + + connServer, connClient := net.Pipe() + client = rpc.NewClient(connClient) + server = rpc.NewServer() + server.Register(service) + go server.ServeConn(connServer) } func BenchmarkEchoInt(b *testing.B) { @@ -55,6 +65,15 @@ func BenchmarkEchoInt(b *testing.B) { } } +func BenchmarkBuiltinEchoInt(b *testing.B) { + args := IntArgs{} + reply := new(IntReply) + for i := 0; i < b.N; i++ { + args.V = int32(i) + client.Call("BenchService.EchoInt", args, reply) + } +} + func BenchmarkEchoString(b *testing.B) { args := StringArgs{"abcdefghijklmnopqrstuvwxyz"} reply := new(StringReply) @@ -62,3 +81,11 @@ func BenchmarkEchoString(b *testing.B) { sessionYang.Call("BenchService.EchoString", args, reply) } } + +func BenchmarkBuiltinEchoString(b *testing.B) { + args := StringArgs{"abcdefghijklmnopqrstuvwxyz"} + reply := new(StringReply) + for i := 0; i < b.N; i++ { + client.Call("BenchService.EchoString", args, reply) + } +}