File: BadReadFile.hs

package info (click to toggle)
haskell-criterion 1.6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: haskell: 1,891; javascript: 811; makefile: 3
file content (17 lines) | stat: -rw-r--r-- 653 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- This example demonstrates the peril of trying to benchmark a
-- function that performs lazy I/O.

import Criterion.Main

main :: IO ()
main = defaultMain [
    -- By using whnfIO, when the benchmark loop goes through an
    -- iteration, we inspect only the first constructor returned after
    -- the file is opened.  Since the entire file must be read in
    -- order for it to be closed, this causes file handles to leak,
    -- and our benchmark will probably crash while running with an
    -- error like this:
    --
    -- openFile: resource exhausted (Too many open files)
    bench "whnfIO readFile" $ whnfIO (readFile "BadReadFile.hs")
  ]