Benchmarks actions and produces statistics such as min, mean, median, standard deviation, and max execution time. Also computes execution time percentiles. Comes with functions to pretty-print the results.
Here's an example showing a benchmark of copying a file:
import qualified Data.ByteString as B import System.IO import Test.BenchPress inpath, outpath :: String inpath = "/tmp/infile" outpath = "/tmp/outfile" blockSize :: Int blockSize = 4 * 1024 copyUsingByteString :: Handle -> Handle -> IO () copyUsingByteString inf outf = go where go = do bs <- B.hGet inf blockSize let numRead = B.length bs if numRead > 0 then B.hPut outf bs >> go else return () main :: IO () main = bench 100 $ do inf <- openBinaryFile inpath ReadMode outf <- openBinaryFile outpath WriteMode copyUsingByteString inf outf hClose outf hClose inf
Running a benchmark
benchmark iters setup teardown action runs
times measuring the execution time of each run.
teardown are run before and after each run respectively.
teardown will be run even if
action raises an exception.
Convenience function that runs a benchmark using
prints timing statistics. Writes output to standard output.
Convenience function that runs several benchmarks using
benchmark and prints a timing statistics summary. Each benchmark
has an associated label that is used to identify the benchmark in
the printed results. Writes output to standard output.
Timing statistics for the benchmark. All measured times are given in milliseconds.