Permalink
Browse files

explicitely fill messages in benchmarks

  • Loading branch information...
1 parent 35d6381 commit 8c2c766aed2652c79113e3412beacb384ef560a3 @galdor galdor committed Oct 10, 2011
Showing with 61 additions and 47 deletions.
  1. +61 −47 examples/official-benchmarks.lisp
@@ -6,22 +6,25 @@
(zmq:with-socket (socket context :sub)
(zmq:setsockopt socket :subscribe "")
(zmq:bind socket address)
- (zmq:with-msg-init (message)
- (flet ((receive-message ()
- (zmq:recv socket message)
- (when (/= (zmq:msg-size message) message-size)
- (format t "message of incorrect size received~%"))))
- (receive-message)
- (let* ((elapsed-time (zmq:with-stopwatch
- (do ((i 0 (1+ i)))
- ((= i (- message-count 1)))
- (receive-message))))
- (throughput (* (/ message-count elapsed-time) 1000000))
- (megabits (/ (* throughput message-size 8) 1000000)))
- (format t "message size: ~A [B]~%" message-size)
- (format t "message count: ~A ~%" message-count)
- (format t "mean throughput ~A [msg/s]~%" (round throughput))
- (format t "mean throughput ~,3F [Mb/s]~%" (round megabits))))))))
+ (let ((data (make-array message-size
+ :element-type '(unsigned-byte 8)
+ :initial-element 0)))
+ (zmq:with-msg-init-data (message data)
+ (flet ((receive-message ()
+ (zmq:recv socket message)
+ (when (/= (zmq:msg-size message) message-size)
+ (format t "message of incorrect size received~%"))))
+ (receive-message)
+ (let* ((elapsed-time (zmq:with-stopwatch
+ (do ((i 0 (1+ i)))
+ ((= i (- message-count 1)))
+ (receive-message))))
+ (throughput (* (/ message-count elapsed-time) 1000000))
+ (megabits (/ (* throughput message-size 8) 1000000)))
+ (format t "message size: ~A [B]~%" message-size)
+ (format t "message count: ~A ~%" message-count)
+ (format t "mean throughput ~A [msg/s]~%" (round throughput))
+ (format t "mean throughput ~,3F [Mb/s]~%" megabits))))))))
(defun remote-thr (address message-size message-count)
(zmq:with-context (context 1)
@@ -49,33 +52,40 @@
(zmq:with-context (context 1)
(zmq:with-socket (socket context :req)
(zmq:connect socket address)
- (zmq:with-msg-init-size (message message-size)
- (let* ((elapsed-time (zmq:with-stopwatch
- (do ((i 0 (1+ i)))
- ((= i roundtrip-count))
- (zmq:send socket message)
- (zmq:recv socket message)
- (unless (eq (zmq:msg-size message) message-size)
- (error "Message of incorrect size ~A received."
- (zmq:msg-size message))))))
- (latency (/ elapsed-time (* roundtrip-count 2))))
- (format t "message size: ~A [B]~%" message-size)
- (format t "roundtrip count: ~A~%" roundtrip-count)
- (format t "average latency: ~,3F [us]~%" latency))))))
+ (let ((data (make-array message-size
+ :element-type '(unsigned-byte 8)
+ :initial-element 97)))
+ (zmq:with-msg-init-data (message data)
+ (let* ((elapsed-time
+ (zmq:with-stopwatch
+ (do ((i 0 (1+ i)))
+ ((= i roundtrip-count))
+ (zmq:send socket message)
+ (zmq:recv socket message)
+ (unless (eq (zmq:msg-size message) message-size)
+ (error "Message of incorrect size ~A received."
+ (zmq:msg-size message))))))
+ (latency (/ elapsed-time (* roundtrip-count 2))))
+ (format t "message size: ~A [B]~%" message-size)
+ (format t "roundtrip count: ~A~%" roundtrip-count)
+ (format t "average latency: ~,3F [us]~%" latency)))))))
(defun inproc-thr (message-size message-count)
(zmq:with-context (context 1)
(zmq:with-socket (socket context :sub)
(zmq:setsockopt socket :subscribe "")
(zmq:bind socket "inproc://thr_test")
- (let ((thread (bordeaux-threads:make-thread
- (lambda ()
- (zmq:with-socket (socket context :pub)
- (zmq:connect socket "inproc://thr_test")
- (do ((i 0 (1+ i)))
- ((= i message-count))
- (zmq:with-msg-init-size (message message-size)
- (zmq:send socket message))))))))
+ (let* ((data (make-array message-size
+ :element-type '(unsigned-byte 8)
+ :initial-element 0))
+ (thread (bordeaux-threads:make-thread
+ (lambda ()
+ (zmq:with-socket (socket context :pub)
+ (zmq:connect socket "inproc://thr_test")
+ (do ((i 0 (1+ i)))
+ ((= i message-count))
+ (zmq:with-msg-init-data (message data)
+ (zmq:send socket message))))))))
(zmq:with-msg-init (message)
(flet ((receive-message ()
(zmq:recv socket message)
@@ -106,16 +116,20 @@
(do ((i 0 (1+ i)))
((= i roundtrip-count))
(zmq:recv socket message)
- (zmq:send socket message))))))))
- (zmq:with-msg-init-size (message message-size)
- (let* ((elapsed-time (zmq:with-stopwatch
- (do ((i 0 (1+ i)))
- ((= i roundtrip-count))
- (zmq:send socket message)
- (zmq:recv socket message)
- (unless (eq (zmq:msg-size message) message-size)
- (error "Message of incorrect size ~A received."
- (zmq:msg-size message))))))
+ (zmq:send socket message)))))))
+ (data (make-array message-size
+ :element-type '(unsigned-byte 8)
+ :initial-element 0)))
+ (zmq:with-msg-init-data (message data)
+ (let* ((elapsed-time
+ (zmq:with-stopwatch
+ (do ((i 0 (1+ i)))
+ ((= i roundtrip-count))
+ (zmq:send socket message)
+ (zmq:recv socket message)
+ (unless (eq (zmq:msg-size message) message-size)
+ (error "Message of incorrect size ~A received."
+ (zmq:msg-size message))))))
(latency (/ elapsed-time (* roundtrip-count 2))))
(format t "message size: ~A [B]~%" message-size)
(format t "roundtrip count: ~A~%" roundtrip-count)

0 comments on commit 8c2c766

Please sign in to comment.