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
executable file 175 lines (152 sloc) 6.7 KB
#!/usr/bin/env runghc
-- dev.hs, for miscellaneous profiling/benchmarking/testing.
-- {-# LANGUAGE DeriveDataTypeable, StandaloneDeriving, DeriveGeneric #-}
-- {-# LANGUAGE NoWarnUnusedImports #-}
-- import System.Environment (getArgs)
-- import Control.Monad.Except
import Criterion.Main
-- import Data.Text.Lazy as LT
import qualified Data.Text as T
-- import System.Environment
import System.TimeIt (timeItT)
import Text.Printf
import Hledger
import Data.Default (def)
-- import Hledger.Utils.Regex (toRegexCI)
-- import Hledger.Utils.Debug
-- import qualified Hledger.Read.JournalReader as JR
-- import qualified Hledger.Read.TimeclockReader as TR
-- import qualified Hledger.Read.TimeclockReaderNoJU as TRNOJU
-- import qualified Hledger.Read.TimeclockReaderPP as TRPP
-- import Control.DeepSeq (NFData)
-- import Data.Data
-- import GHC.Generics (Generic)
-- import Text.Regex.TDFA (Regex(..))
--
-- instance Generic Regex
-- instance NFData Regex
-- deriving instance Data (Regex)
-- deriving instance Typeable (Regex)
-- deriving instance Generic (Regex)
-- instance NFData Regex
journal =
-- "examples/10000x1000x10.journal"
"examples/10000x1000x10.journal"
timeclock = "examples/sample.timeclock"
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)
main = do
-- putStrLn $ regexReplaceCI "^aa" "xx" "aa:bb:cc:dd:ee"
(_t0,_j) <- timeit ("read "++journal) $ either error id <$> readJournalFile def journal
return ()
-- printf "Total: %0.2fs\n" (sum [t0,t1,t2,t3,t4])
-- -- read the input journal
-- s <- readFile journal
-- j <- either error id <$> readJournal def Nothing s
-- -- putStrLn $ show $ length $ jtxns j -- sanity check we parsed it all
-- let accts = map paccount $ journalPostings j
-- Criterion.Main.defaultMainWith defaultConfig $ [
-- -- bench ("toRegexCI") $ whnf toRegexCI "^aa"
-- -- ,bench ("toRegexCI") $ whnfIO (return $ toRegexCI "^aa")
-- -- ,bench ("toRegexCI x 1000") $ nfIO $ sequence_ (map (return . toRegexCI) (replicate 1000 "^aa"))
-- -- bench ("regexReplaceCI") $ nf (regexReplaceCI "aa" "xx") "aa:bb:cc:dd:ee:1"
-- -- ,bench ("regexReplaceCI x 1000") $ nf (map (regexReplaceCI "bb" "xx")) (replicate 1000 "aa:bb:cc:dd:ee;2")
-- -- ,bench ("regexReplaceCIMemo") $ nf (regexReplaceCIMemo "ee" "xx") "aa:bb:cc:dd:ee:5"
-- -- ,bench ("regexReplaceCIMemo x 1000") $ nf (map (regexReplaceCIMemo "ff" "xx")) (replicate 1000 "aa:bb:cc:dd:ee:6")
-- bench ("apply one regex alias to one posting") $
-- nf (map (accountNameApplyAliases [RegexAlias "^1:" "x:"])) (map paccount $ take 1 $ journalPostings j)
-- -- ,bench ("apply one regex alias to 20000 postings") $
-- -- nf (map (accountNameApplyAliases [RegexAlias "^1:" "x:"])) (map paccount $ journalPostings j)
-- -- ,bench ("apply 3 regex aliases to 20000 postings") $
-- -- nf (map (accountNameApplyAliases [
-- -- RegexAlias "^1:" "x:"
-- -- ,RegexAlias "^2:" "x:"
-- -- ,RegexAlias "^3:" "x:"
-- -- ])) accts
-- -- ,bench ("readJournal") $ whnfIO $
-- -- either error id <$>
-- -- readJournal def Nothing s
-- -- ,bench ("readJournal with aliases") $ whnfIO $
-- -- either error id <$>
-- -- readJournal def Nothing (
-- -- unlines [
-- -- "alias /^fb:/=xx \n"
-- -- ,"alias /^f1:/=xx \n"
-- -- ,"alias /^e7:/=xx \n"
-- -- ] ++ s)
-- ]
-- (t0,j0) <- timeReadJournal ("read "++journal) s
-- (t0',j0') <- timeReadJournal ("read "++journal++" again") s
-- (t1,j1) <- timeReadJournal ("read "++journal++"with 3 simple aliases")
-- (unlines [
-- "alias fb=xx \n"
-- ,"alias f1=xx \n"
-- ,"alias e7=xx \n"
-- ] ++ s)
-- (t1',j1') <- timeReadJournal ("read "++journal++"with 3 simple aliases again")
-- (unlines [
-- "alias fb=xx \n"
-- ,"alias f1=xx \n"
-- ,"alias e7=xx \n"
-- ] ++ s)
-- (t2,j2) <- timeReadJournal ("read "++journal++"with 3 regex aliases")
-- (unlines [
-- "alias /^fb:/=xx \n"
-- ,"alias /^f1:/=xx \n"
-- ,"alias /^e7:/=xx \n"
-- ] ++ s)
-- (t2',j2') <- timeReadJournal ("read "++journal++"with 3 regex aliases again")
-- (unlines [
-- "alias /^fb:/=xx \n"
-- -- ,"alias /^f1:/=xx \n"
-- -- ,"alias /^e7:/=xx \n"
-- ] ++ s)
-- putStrLn $ show (
-- -- j0,
-- -- j0',
-- -- j1,
-- -- j1',
-- -- j2,
-- j2'
-- ) -- force evaluation, though it seems not to be needed
-- return ()
--timeReadJournal :: String -> T.Text -> IO (Double, Journal)
--timeReadJournal msg s = timeit msg $ either error id <$> readJournal def Nothing s
-- benchmark timeclock parsing
-- s <- readFile inputtimeclock
-- putStrLn $ show $ length s
-- let s = unlines [
-- "i 2009/03/27 09:00:00 projects:a",
-- "o 2009/03/27 17:00:34",
-- "i 2009/03/31 22:21:45 personal:reading:online",
-- "o 2009/04/01 02:00:34",
-- "i 2009/04/02 09:00:00 projects:b",
-- "o 2009/04/02 17:00:34"
-- ]
-- -- let output = return . const -- putStrLn.show
-- -- withArgs ["-l"] $ defaultMain [bench "timeclock polyparse" $ nfIO $ runExceptT $ TRPP.parseJournalWith' TRPP.timeclockFile False "" s]
-- defaultMain [
-- -- bench ("read "++inputtimeclock++" with parsec") $ nfIO $ runExceptT (TR.parse Nothing False "" s) >>= output
-- -- bench ("read "++inputtimeclock++" with parsec, no ju") $ nfIO $ runExceptT (TRNOJU.parse Nothing False "" s) >>= output,
-- -- bench ("read "++inputtimeclock++" polyparse") $ nfIO $ runExceptT (TRPP.parse Nothing False "" s) >>= output
-- ]
-- return ()
-- 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
-- (t4,_) <- timeit ("stats") $ stats opts j
-- printf "Total: %0.2fs\n" (sum [t0,t1,t2,t3,t4])
-- 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)