[Haskell-cafe] Is it safe to use unsafePerformIO here?

Daniel Fischer daniel.is.fischer at web.de
Tue Sep 15 15:29:18 EDT 2009


Am Dienstag 15 September 2009 21:13:02 schrieb Daniel Fischer:
> Still, the body should be read lazily.
> I'm not sure, but the tracing message may be output because of its
> position.
>
> With
>
> where
>     readBody = withFile fn ReadMode $ \h -> do
>         b <- hGetContents h
>         seq b $ return (trace ("Read body from: " ++ fn) b)
>
> there's no tracing output.

Yes, tested with 
-rw-r--r-- 1 me users 243M 15. Sep 21:17 file1.txt
-rw-r--r-- 1 me users 243M 15. Sep 21:18 file2.txt

original:

./cparis2 +RTS -Sstderr                                        
    Alloc    Copied     Live    GC    GC     TOT     TOT  Page Flts
    bytes     bytes     bytes  user  elap    user    elap          
Read body: file1.txt                                               
Read body: file2.txt                                               
2                                                                  
3                                                                  
   427996      1408     18620  0.00  0.00    0.00    0.00    0    0  (Gen:  1)
     4096                      0.00  0.00                                     

         432,092 bytes allocated in the heap
           1,408 bytes copied during GC     
          18,620 bytes maximum residency (1 sample(s))
          22,340 bytes maximum slop                   
               1 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s elapsed
  Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s elapsed

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    0.00s  (  0.00s elapsed)
  GC    time    0.00s  (  0.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    0.00s  (  0.00s elapsed)

  %GC time       0.0%  (8.3% elapsed)

  Alloc rate    432,092,000,000 bytes per MUT second

  Productivity 100.0% of total user, 0.1% of total elapsed

moved trace:

./CParis +RTS -Sstderr
    Alloc    Copied     Live    GC    GC     TOT     TOT  Page Flts
    bytes     bytes     bytes  user  elap    user    elap
2
3
   426100      1408     18476  0.00  0.00    0.00    0.00    0    0  (Gen:  1)
     4096                      0.00  0.00

         430,196 bytes allocated in the heap
           1,408 bytes copied during GC
          18,476 bytes maximum residency (1 sample(s))
          22,484 bytes maximum slop
               1 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s elapsed
  Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s elapsed

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    0.00s  (  0.00s elapsed)
  GC    time    0.00s  (  0.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    0.00s  (  0.00s elapsed)

  %GC time       0.0%  (9.3% elapsed)

  Alloc rate    107,549,000 bytes per MUT second

  Productivity 100.0% of total user, 230.3% of total elapsed



More information about the Haskell-Cafe mailing list