@@ -40,7 +40,7 @@ import Control.Applicative ((<**>))
40
40
import Control.Concurrent (getNumCapabilities )
41
41
import Control.Concurrent.Async
42
42
import Control.Concurrent.MVar
43
- import Control.Monad (forM , forM_ , void , when )
43
+ import Control.Monad (forM , forM_ , guard , void , when )
44
44
import Control.Monad.ST (ST , runST )
45
45
import Control.Monad.Trans.State.Strict (runState , state )
46
46
import qualified Data.ByteString.Short as BS
@@ -72,12 +72,17 @@ import System.Directory (createDirectoryIfMissing)
72
72
import System.IO
73
73
import System.Mem (performMajorGC )
74
74
import qualified System.Random as Random
75
+ import qualified Text.ParserCombinators.ReadPrec as Lex
75
76
import Text.Printf (printf )
76
77
import Text.Read (Read (.. ))
78
+ import qualified Text.Read as Lex
79
+ import qualified Text.Read.Lex as Lex
77
80
78
81
import Database.LSMTree.Extras (groupsOfN )
79
82
import Database.LSMTree.Internal.ByteString (byteArrayToSBS )
80
83
84
+ import System.Environment
85
+
81
86
-- We should be able to write this benchmark
82
87
-- using only use public lsm-tree interface
83
88
import qualified Database.LSMTree.Simple as LSM
@@ -172,7 +177,15 @@ instance Show PaymentRate where
172
177
173
178
instance Read PaymentRate where
174
179
175
- readPrec = PaymentRate . toRational <$> (readPrec @ Double )
180
+ readPrec =
181
+ let pFloat = toRational <$> (readPrec @ Double )
182
+ pFract = do
183
+ num <- Lex. readP_to_Prec $ const Lex. readDecP
184
+ Lex. Symbol sep <- Lex. lexP
185
+ guard $ head sep `elem` (" /:%" :: String )
186
+ den <- Lex. readP_to_Prec $ const Lex. readDecP
187
+ pure $ num % den
188
+ in PaymentRate <$> Lex. choice [ pFract, pFloat ]
176
189
177
190
-------------------------------------------------------------------------------
178
191
-- command line interface
@@ -456,12 +469,18 @@ doDryRun' gopts opts = do
456
469
-- |
457
470
-- From StackOverflow: https://stackoverflow.com/a/30938328
458
471
renderRational :: Int -> Rational -> String
459
- renderRational len rat = sign <> shows d (" ." ++ take len (go next) )
472
+ renderRational len rat = sign <> shows prefix (" ." ++ suffix )
460
473
where
461
474
sign
462
475
| num < 0 = " -"
463
476
| otherwise = " "
464
- (d, next) = abs num `quotRem` den
477
+
478
+ (prefix, next) = abs num `quotRem` den
479
+
480
+ suffix = case next of
481
+ 0 -> " 0"
482
+ n -> take len $ go n
483
+
465
484
num = numerator rat
466
485
den = denominator rat
467
486
go 0 = " "
@@ -541,6 +560,8 @@ doRun gopts opts = do
541
560
| pipelined opts = pipelinedIterations h
542
561
| otherwise = sequentialIterations h
543
562
563
+ print $ deriveFileNameForPlot gopts opts
564
+
544
565
refRNG <- newIORef $ initGen
545
566
(initialSize gopts)
546
567
(batchSize opts)
@@ -619,6 +640,37 @@ fillBetween title vs = Plot.liftEC $ do
619
640
Plot. plot_fillbetween_style .= Plot. solidFillStyle color
620
641
Plot. plot_fillbetween_values .= vs
621
642
643
+ deriveFileNameForPlot :: GlobalOpts -> RunOpts -> FilePath
644
+ deriveFileNameForPlot gOpts rOpts =
645
+ let partTable = show $ tableCount gOpts
646
+ partWidth = List. intercalate " _" . fmap Fold. toList . groupsOfN 3 . reverse . show $ initialSize gOpts
647
+ in Fold. fold
648
+ [ " benchmark"
649
+ , partTable
650
+ , " ×"
651
+ , partWidth
652
+ , " .png"
653
+ ]
654
+
655
+ {-
656
+ data GlobalOpts = GlobalOpts
657
+ { rootDir :: !FilePath -- ^ session directory.
658
+ , tableCount :: !Int -- ^ Number of tables in the benchmark
659
+ , initialSize :: !Int
660
+ }
661
+ deriving stock Show
662
+
663
+ data RunOpts = RunOpts
664
+ { batchCount :: !Int
665
+ , batchSize :: !Int
666
+ , check :: !Bool
667
+ , seed :: !Word64
668
+ , pipelined :: !Bool
669
+ , payRate :: !PaymentRate
670
+ }
671
+ deriving stock Show
672
+ -}
673
+
622
674
-------------------------------------------------------------------------------
623
675
-- sequential
624
676
-------------------------------------------------------------------------------
@@ -913,6 +965,7 @@ main = do
913
965
putStrLn " To benchmark in release mode, pass:"
914
966
putStrLn " --project-file=cabal.project.release"
915
967
#endif
968
+ getArgs >>= Fold. traverse_ print
916
969
(gopts, cmd) <- O. customExecParser prefs cliP
917
970
print gopts
918
971
print cmd
0 commit comments