Created
May 19, 2015 11:21
-
-
Save taotetek/2d2e6746329b2ff2e6f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func benchmarkChanneler(size int, b *testing.B) { | |
pullSock := NewSock(Pull) | |
pullSock.Bind("inproc://benchChan") | |
defer pullSock.Destroy() | |
channeler := NewChanneler(pullSock, false) | |
time.Sleep(10 * time.Millisecond) | |
go func() { | |
pushSock := NewSock(Push) | |
defer pushSock.Destroy() | |
err := pushSock.Connect("inproc://benchChan") | |
if err != nil { | |
panic(err) | |
} | |
payload := make([]byte, size) | |
for i := 0; i < b.N; i++ { | |
_, err = pushSock.Write(payload) | |
if err != nil { | |
panic(err) | |
} | |
} | |
}() | |
for i := 0; i < b.N; i++ { | |
msg := <-channeler.RecvChan | |
if len(msg[0]) != size { | |
panic("msg too small") | |
} | |
} | |
channeler.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment