For more reliable performance measures, the criterion
package comes in handy. The package description points out a major flaw in using simple procedures to time pure code.
"Because GHC optimizes aggressively when compiling with -O, it is potentially easy to write innocent-looking benchmark code that will only be evaluated once, for which all but the first iteration of the timing loop will be timing the cost of doing nothing."
Create a small.txt
file with a few words. Create a file, big.txt
, filled with text as follows:
$ wget norvig.com/big.txt
Install the criterion
library as follows:
$ cabal install criterion
Import the package as follows:
import Criterion.Main
Define the I/O function we wish to time as follows:
splitUp filename = readFile filename >>= return . words
Benchmark the desired function as follows:
main = defaultMain [ bgroup "splitUp" [ bench "big" $ nfIO $ splitUp "big.txt" , bench "small...