-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
212 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- This example demonstrates how to correctly benchmark a function | ||
-- that performs lazy I/O. | ||
|
||
import Criterion.Main | ||
|
||
main :: IO () | ||
main = defaultMain [ | ||
-- Because we are using nfIO here, the entire file will be read on | ||
-- each benchmark loop iteration. This will cause the associated | ||
-- file handle to be eagerly closed every time. | ||
bench "nfIO readFile" $ nfIO (readFile "GoodReadFile.hs") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I get an error due to this change when building with GHC 7.6.3. I'm testing now whether it works with 7.8.3.