Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7418 closed bug (worksforme)

Writing to stderr is 7x slower than writing to stdout

Reported by: SimonHengel Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 7.6.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

For some reason printing to stderr is significantly slower than printing to stdout.

I came across this because I realized that simple QuickCheck properties are unnecessarily slow. QuickCheck writes a lot of output to stderr, overriding old output with \b.

Here are some stats:

GHC 7.6.1 / xterm / stdout:

main = sequence_ . replicate 10000 $ hPutStr stdout "foobarbaz" >> hFlush stdout
$ ghc main.hs && time ./main
...
real    0m0.070s
user    0m0.016s
sys     0m0.032s

GHC 7.6.1 / xterm / stderr:

main = sequence_ . replicate 10000 $ hPutStr stderr "foobarbaz" >> hFlush stderr
$ ghc main.hs && time ./main
...
real    0m0.538s
user    0m0.112s
sys     0m0.228s

If I do the same thing in C, then there is no performance difference.

Change History (3)

comment:1 Changed 7 years ago by parcs

By default stdout is buffered and stderr is not. If you do hSetBuffering stderr LineBuffering in the second program then it's just as fast as the first program.

QuickCheck should probably be patched to enable buffering on stderr.

comment:2 Changed 7 years ago by igloo

difficulty: Unknown
Resolution: worksforme
Status: newclosed

Thanks for the report, but I agreed with parcs: the difference is caused by buffering, so this is not a bug in GHC.

comment:3 Changed 7 years ago by SimonHengel

Thanks a lot for the clarification.

Note: See TracTickets for help on using tickets.