Skip to content

Instantly share code, notes, and snippets.

@taotetek
Created May 19, 2015 11:21
Show Gist options
  • Save taotetek/2d2e6746329b2ff2e6f8 to your computer and use it in GitHub Desktop.
Save taotetek/2d2e6746329b2ff2e6f8 to your computer and use it in GitHub Desktop.
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