From 11a6cb925f7ff3d17f48edccc886839b4d49ef0b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 7 Sep 2009 11:00:20 +0200 Subject: Ruby binding functional --- perf/ruby/remote_lat.rb | 64 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'perf/ruby/remote_lat.rb') diff --git a/perf/ruby/remote_lat.rb b/perf/ruby/remote_lat.rb index 953e579..9387fe1 100644 --- a/perf/ruby/remote_lat.rb +++ b/perf/ruby/remote_lat.rb @@ -18,44 +18,36 @@ require 'librbzmq' -class AssertionFailure < StandardError +if ARGV.length != 3 + puts "usage: remote_lat " + Process.exit end -def assert(bool, message = 'assertion failure') - raise AssertionFailure.new(message) unless bool +connect_to = ARGV[0] +message_size = ARGV[1].to_i +roundtrip_count = ARGV[2].to_i + +ctx = Context.new(1, 1) +s = Socket.new(ctx, REQ); +s.connect(connect_to); + +msg = "#{'0'*message_size}" + +start_time = Time.now + +for i in 0...roundtrip_count do + s.send(msg, 0) + msg = s.recv(0) end - if ARGV.length != 4 - puts "usage: remote_lat " + \ - " " - Process.exit - end - - in_interface = ARGV[0] - out_interface = ARGV[1] - message_size = ARGV[2] - roundtrip_count = ARGV[3] - - # Create 0MQ transport. - rb_zmq = Zmq.new() - - # Create the wiring. - context = rb_zmq.context(1,1) - in_socket = rb_zmq.socket(context, ZMQ_SUB) - out_socket = rb_zmq.socket(context, ZMQ_PUB) - - # Connect. - rb_zmq.connect(in_socket, in_interface.to_s) - rb_zmq.connect(out_socket, out_interface.to_s) - - # The message loop. - for i in 0...roundtrip_count.to_i do - data = rb_zmq.recv(in_socket, ZMQ_NOBLOCK) - assert(rb_zmq.msg_size(data.msg) == message_size.to_i) - rb_zmq.send(out_socket, data.msg, ZMQ_NOBLOCK) - end - - # Wait till all messages are sent. - sleep 2 - +end_time = Time.now + +elapsed = (end_time.to_f - start_time.to_f) * 1000000 +latency = elapsed / roundtrip_count / 2 + +puts "message size: %i [B]" % message_size +puts "roundtrip count: %i" % roundtrip_count +puts "mean latency: %.3f [us]" % latency + + -- cgit v1.2.3