bench-thf.rkt 995 B

1234567891011121314151617181920212223242526272829303132333435
  1. #lang racket/base
  2. (module+ main
  3. (require racket/tcp)
  4. (define PORT 8000)
  5. (define RESPONSE #"HTTP/1.1 200 OK\r\nContent-Length: 1\r\n\r\n!")
  6. (define END (bytes-length RESPONSE))
  7. (define BUFFER-SIZE 64)
  8. (define BUFFER (make-bytes BUFFER-SIZE))
  9. (define const-eof (λ (x) eof))
  10. (define l (tcp-listen PORT 10 #t #f))
  11. (printf "Ready\n")
  12. (flush-output)
  13. (let accept-loop ()
  14. (define-values (from to) (tcp-accept l))
  15. (thread
  16. (λ ()
  17. (let conn-loop ()
  18. (define read-k
  19. ;; XXX This drops performance from about 132k/s to 120k/s,
  20. ;; but is necessary because of crashing the benchmarks
  21. (with-handlers ([exn:fail? const-eof])
  22. (read-bytes-avail!* BUFFER from 0 BUFFER-SIZE)))
  23. (cond
  24. [(eof-object? read-k)
  25. (close-input-port from)
  26. (close-output-port to)]
  27. [else
  28. (write-bytes-avail* RESPONSE to 0 END)
  29. (conn-loop)]))))
  30. (accept-loop)))