Permalink
Switch branches/tags
hledger-web-1.10 hledger-web-1.9.2 hledger-web-1.9.1 hledger-web-1.9 hledger-web-1.5.1 hledger-web-1.5 hledger-web-1.4 hledger-web-1.3.2 hledger-web-1.3.1 hledger-web-1.3 hledger-web-1.2 hledger-web-1.1 hledger-web-1.0.1 hledger-web-1.0 hledger-web-0.27 hledger-web-0.26 hledger-web-0.25.1 hledger-web-0.25 hledger-web-0.24.1 hledger-web-0.24 hledger-web-0.23.3 hledger-web-0.23.2 hledger-web-0.23.1 hledger-web-0.23 hledger-web-0.21.3 hledger-web-0_19 hledger-web-0_17_1 hledger-web-0_16_5 hledger-web-0_16_4 hledger-web-0_16_3 hledger-web-0_16_2 hledger-web-0_15_3 hledger-web-0_15_1 hledger{,-vty,-chart}-0_15_1,_hledger-web-0_15_2 hledger-ui-1.10.1 hledger-ui-1.10 hledger-ui-1.9.1 hledger-ui-1.9 hledger-ui-1.5 hledger-ui-1.4 hledger-ui-1.3.1 hledger-ui-1.3 hledger-ui-1.2 hledger-ui-1.1.2 hledger-ui-1.1.1 hledger-ui-1.1 hledger-ui-1.0.5 hledger-ui-1.0.4 hledger-ui-1.0.3 hledger-ui-1.0.2 hledger-ui-1.0.1 hledger-ui-1.0 hledger-ui-0.27.5 hledger-ui-0.27.4 hledger-ui-0.27.3 hledger-ui-0.27.2 hledger-ui-0.27.1 hledger-ui-0.27 hledger-lib-1.10 hledger-lib-1.9.1 hledger-lib-1.9 hledger-lib-1.5.1 hledger-lib-1.5 hledger-lib-1.4 hledger-lib-1.3.2 hledger-lib-1.3.1 hledger-lib-1.3 hledger-lib-1.2 hledger-lib-1.1 hledger-lib-1.0.1 hledger-lib-1.0 hledger-lib-0.27.1 hledger-lib-0.27 hledger-lib-0.26 hledger-lib-0.25.1 hledger-lib-0.25 hledger-lib-0.24.1 hledger-lib-0.24 hledger-lib-0.23.3 hledger-lib-0.23.2 hledger-lib-0.23.1 hledger-lib-0.23 hledger-irr-0.1.1.4 hledger-irr-0.1.1.3 hledger-irr-0.1.1.2 hledger-irr-0.1.1.1 hledger-irr-0.1.1 hledger-api-1.10 hledger-api-1.9.1 hledger-api-1.9 hledger-api-1.5 hledger-api-1.4 hledger-api-1.3.1 hledger-api-1.3 hledger-api-1.2 hledger-api-1.1 hledger-api-1.0 hledger-1.10 hledger-1.9.1 hledger-1.9
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (53 sloc) 2.14 KB
-- bench
-- By default, show approximate times for some standard hledger operations on a sample journal.
-- With --criterion, show accurate times (slow).
import Criterion.Main (defaultMainWith, defaultConfig, bench, nfIO)
-- import QuickBench (defaultMain)
import Data.Default
import System.Directory (getCurrentDirectory)
import System.Environment (getArgs, withArgs)
import System.TimeIt (timeItT)
import Text.Printf
import Hledger.Cli
-- sample journal file to use for benchmarks
inputfile = "bench/10000x1000x10.journal"
outputfile = "/dev/null" -- hide output of benchmarked commands (XXX unixism)
-- outputfile = "-" -- show output of benchmarked commands
main = do
-- withArgs ["--quickbench"] $ do
-- withArgs ["--criterion"] $ do
args <- getArgs
if "--criterion" `elem` args
then
withArgs [] benchWithCriterion
else
-- if "--quickbench" `elem` args
-- then
-- benchWithQuickbench
-- else
benchWithTimeit
benchWithTimeit = do
getCurrentDirectory >>= printf "Benchmarking hledger in %s with timeit\n"
let opts = defcliopts{output_file_=Just outputfile}
(t0,j) <- timeit ("read "++inputfile) $ either error id <$> readJournalFile def inputfile
(t1,_) <- timeit ("print") $ print' opts j
(t2,_) <- timeit ("register") $ register opts j
(t3,_) <- timeit ("balance") $ balance opts j
printf "Total: %0.2fs\n" (sum [t0,t1,t2,t3])
timeit :: String -> IO a -> IO (Double, a)
timeit name action = do
printf "%s%s" name (replicate (40 - length name) ' ')
(t,a) <- timeItT action
printf "[%.2fs]\n" t
return (t,a)
benchWithCriterion = do
getCurrentDirectory >>= printf "Benchmarking hledger in %s with criterion\n"
let opts = defcliopts{output_file_=Just "/dev/null"}
j <- either error id <$> readJournalFile def inputfile
Criterion.Main.defaultMainWith defaultConfig $ [
bench ("read "++inputfile) $ nfIO $ (either error const <$> readJournalFile def inputfile),
bench ("print") $ nfIO $ print' opts j,
bench ("register") $ nfIO $ register opts j,
bench ("balance") $ nfIO $ balance opts j,
bench ("stats") $ nfIO $ stats opts j
]