Skip to content

Instantly share code, notes, and snippets.

@paddor
Created November 13, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddor/bbbcc4d187be5e50470b49692e9b21ea to your computer and use it in GitHub Desktop.
Save paddor/bbbcc4d187be5e50470b49692e9b21ea to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require "cztop"
require "benchmark"
if ARGV.size != 2
abort <<MSG
Usage: #{$0} <message-size> <message-count>
MSG
end
MSG_SIZE = Integer(ARGV[0]) # bytes
MSG_COUNT = Integer(ARGV[1]) # number of messages
MSG = "X" * MSG_SIZE
tms = Benchmark.measure do
t1 = Thread.new do
s = CZTop::Socket::PAIR.new("@inproc://perf")
ffi_sock = s.ffi_delegate
MSG_COUNT.times do
s = CZMQ::FFI::Zstr.recv(ffi_sock).read_string
raise "wrong message size" if s.size != MSG_SIZE
end
end
t2 = Thread.new do
s = CZTop::Socket::PAIR.new(">inproc://perf")
ffi_sock = s.ffi_delegate
MSG_COUNT.times do
CZMQ::FFI::Zstr.send(ffi_sock, MSG)
end
end
[t1, t2].each(&:join)
end
elapsed = tms.real
throughput = MSG_COUNT / elapsed
megabits = (throughput * MSG_SIZE * 8) / 1_000_000
puts "message size: #{MSG_SIZE} [B]"
puts "message count: #{MSG_COUNT}"
puts "elapsed time: %.3f [s]" % elapsed
puts "mean throughput: %d [msg/s]" % throughput
puts "mean throughput: %.3f [Mb/s]" % megabits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment