[Haskell-cafe] First call to putStr takes far more time than subsequent calls

Brandon Allbery allbery.b at gmail.com
Thu Jul 9 20:24:13 UTC 2015

On Thu, Jul 9, 2015 at 4:17 PM, Ben Gunton <ben.gunton at gmail.com> wrote:

> In this example, the first putStr inside the replicateM_ takes far longer
> than subsequent putStrs. If I add in a putStr at the top (the commented
> line), each iteration takes the same. (Though I presume I just shifted the
> long execution to the putStr on top).

If I had to guess, delayed setup of the Handle associated with stdout. This
will include setting up buffering (including querying the OS to find out
whether output is a tty-like device or not, so as to enable or disable
block buffering; note that this may be especially expensive on Windows,
where there is IIRC no simple way to determine whether running in e.g. a
cmd.exe window or not, as the OS has no concept of pseudo-ttys); also,
setting up output encoding and such. Probably also other details.

brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150709/ea6a4806/attachment.html>

More information about the Haskell-Cafe mailing list