Skip to content

Commit

Permalink
Add BenchmarkBuiltinEchoInt,BenchmarkBuiltinEchoString
Browse files Browse the repository at this point in the history
  • Loading branch information
朱熠锷 authored and 朱熠锷 committed Jan 17, 2017
1 parent 0ede23b commit 9870fa4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bidirpc

import (
"net"
"net/rpc"
"testing"
)

Expand Down Expand Up @@ -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) {
Expand All @@ -55,10 +65,27 @@ 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)
for i := 0; i < b.N; i++ {
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)
}
}

0 comments on commit 9870fa4

Please sign in to comment.