#lang racket (define echoer (thread (lambda () (let loop () (define source (thread-receive)) (thread-send source #t) (loop))))) (define LIMIT 10000000) (define start-time (current-inexact-milliseconds)) (let loop ((n 0)) (when (< n LIMIT) (thread-send echoer (current-thread)) (thread-receive) (loop (+ n 1)))) (define stop-time (current-inexact-milliseconds)) (define deltasec (/ (- stop-time start-time) 1000.0)) (define roundtrip-hz (/ LIMIT deltasec)) (printf "~v roundtrips/sec, i.e. ~v messages/sec\n" roundtrip-hz (* 2 roundtrip-hz)) (printf "That's a per-message latency of ~v\n" (/ (* 2 roundtrip-hz)))