mirror of
https://github.com/luxfi/czmq.git
synced 2026-10-30 16:59:02 +00:00
- Updated module path to github.com/luxfi/czmq/v4 - All imports and dependencies updated for v4 compatibility - Tests passing with ZeroMQ libraries from Homebrew
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"time"
|
|
|
|
czmq "github.com/luxfi/czmq/v4"
|
|
)
|
|
|
|
func main() {
|
|
var messageSize = flag.Int("message_size", 0, "size of message")
|
|
var messageCount = flag.Int("message_count", 0, "number of messages")
|
|
flag.Parse()
|
|
|
|
pullSock, err := czmq.NewPull("inproc://test")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer pullSock.Destroy()
|
|
|
|
go func() {
|
|
pushSock, err := czmq.NewPush("inproc://test")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer pushSock.Destroy()
|
|
for i := 0; i < *messageCount; i++ {
|
|
payload := make([]byte, *messageSize)
|
|
err = pushSock.SendMessage([][]byte{payload})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}()
|
|
|
|
startTime := time.Now()
|
|
for i := 0; i < *messageCount; i++ {
|
|
msg, err := pullSock.RecvMessage()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if len(msg) != 1 {
|
|
panic("msg too small")
|
|
}
|
|
}
|
|
endTime := time.Now()
|
|
elapsed := endTime.Sub(startTime)
|
|
throughput := float64(*messageCount) / elapsed.Seconds()
|
|
megabits := float64(throughput*float64(*messageSize)*8.0) / 1e6
|
|
|
|
log.Printf("message size: %d", *messageSize)
|
|
log.Printf("message count: %d", *messageCount)
|
|
log.Printf("test time (seconds): %f", elapsed.Seconds())
|
|
log.Printf("mean throughput: %f [msg/s]", throughput)
|
|
log.Printf("mean throughput: %f [Mb/s]", megabits)
|
|
}
|