[racket] Performance of open-output-nowhere

From: Antonio Menezes Leitao (antonio.menezes.leitao at ist.utl.pt)
Date: Thu Jul 24 04:27:42 EDT 2014

Hi,

While trying to benchmark some of my code, I tried to minimize the time
spend on predefined IO functions, such as write-byte & friends, by using
the port returned by open-output-nowhere, expecting that it would be faster
than using, e.g., open-output-bytes, which has to accumulate the output.

However, contrary to my expectations, it turns out that using
open-output-nowhere is 10 times slower that using open-output-bytes.

Here is one example:

#lang racket
(define (test i n p)
  (time (for ([l (in-range n)])
          (write-byte i p))))

(test 123 100000000 (open-output-bytes))
(test 123 100000000 (open-output-nowhere))

I'm getting:

cpu time: 2860 real time: 2854 gc time: 32
cpu time: 28906 real time: 28904 gc time: 125

What's causing this difference?

Best,
António.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140724/feeb0c67/attachment.html>

Posted on the users mailing list.