Skip to content

Commit 218d83f

Browse files
committed
Merge options for space and time
1 parent c8455fb commit 218d83f

File tree

3 files changed

+33
-49
lines changed

3 files changed

+33
-49
lines changed

bench/Command.hs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ module Command
33
(
44
Option (..),
55
Output (..),
6-
CommandTime (..),
6+
Command (..),
77
ListOption (..),
8-
CommandSpace (..),
98
StaOut (..),
109
CommandDataSize (..),
11-
commandTime,
12-
commandSpace,
10+
commandP,
1311
commandDataSize
1412
)
1513

@@ -46,11 +44,9 @@ type Graph = String
4644
data ListOption = Benchs | Libs
4745
deriving (Show, Eq)
4846

49-
data CommandTime = List ListOption | Run (Maybe Option) (Maybe [String]) Output (Maybe [Lib]) Bool Bool [(Graph,Int)]
47+
data Command = List ListOption | Run (Maybe Option) (Maybe [String]) Output (Maybe [Lib]) Bool Bool [(Graph,Int)]
5048
deriving (Show, Eq)
5149

52-
data CommandSpace = ListS ListOption | RunS (Maybe [String]) (Maybe [String]) Output (Maybe [Lib])
53-
5450
newtype CommandDataSize = RunD [(Graph,Int)]
5551

5652
partOpt :: Parser Option
@@ -69,7 +65,7 @@ libOpt :: Parser Lib
6965
libOpt = strOption (long "lib" <> short 'l' <> metavar "LIBNAME" <> help "Benchmark only the library with LIBNAME. Can be used multiple times")
7066

7167
graphOpt :: Parser (Graph,Int)
72-
graphOpt = option auto (long "graph" <> short 'g' <> metavar "GRAPH" <> help "graph to be tested")
68+
graphOpt = option auto (long "graph" <> short 'g' <> metavar "GRAPH" <> help "graph to be tested (IGNORED FOR SPACE BENCHMARKS)")
7369

7470
graphsOpt :: Parser [(Graph,Int)]
7571
graphsOpt = many graphOpt
@@ -94,27 +90,27 @@ figFlag = pure Nothing
9490
#endif
9591

9692
benchWithCreation :: Parser Bool
97-
benchWithCreation = flag False True $ long "bench-with-creation" <> short 'b' <> help "When set, will benchmark also the graph-creation function. See README"
93+
benchWithCreation = flag False True $ long "bench-with-creation" <> short 'b' <> help "When set, will benchmark also the graph-creation function. See README (IGNORED FOR SPACE BENCHMARKS)"
9894

9995
benchLittleOne :: Parser Bool
100-
benchLittleOne = flag False True $ long "dont-bench-little-ones" <> short 'i' <> help "When set, will only benchmark the largest graphs"
96+
benchLittleOne = flag False True $ long "dont-bench-little-ones" <> short 'i' <> help "When set, will only benchmark the largest graphs (IGNORED FOR SPACE BENCHMARKS)"
10197

10298
staFlag :: Parser StaOut
10399
staFlag = option auto $ long "standardOutput" <> short 'd' <> value Ascii <> help ("The standard output, can be: " ++ intercalate ", " staOutCons) <> completeWith staOutCons
104100

105101
output :: Parser Output
106102
output = Output <$> sumFlag <*> optional saveOpt <*> staFlag <*> figFlag
107103

108-
runCom :: Parser CommandTime
104+
runCom :: Parser Command
109105
runCom = Run <$> optional options <*> optional notOnlyOpt <*> output <*> optional (some libOpt) <*> benchWithCreation <*> benchLittleOne <*> graphsOpt
110106

111107
listOpt :: Parser ListOption
112108
listOpt = flag' Benchs (long "benchs") <|> flag' Libs (long "libs")
113109

114-
listCom :: Parser CommandTime
110+
listCom :: Parser Command
115111
listCom = List <$> listOpt
116112

117-
command' :: Parser CommandTime
113+
command' :: Parser Command
118114
command' = subparser
119115
( command "list" list
120116
<> command "run" run
@@ -129,34 +125,13 @@ command' = subparser
129125
<> progDesc "List benchmarks"
130126
<> header "Help" )
131127

132-
commandTime :: ParserInfo CommandTime
133-
commandTime = info (command' <**> helper)
134-
( fullDesc
135-
<> progDesc "Benchmark time of functions on different graphs libraries"
136-
<> header "Help" )
137-
138-
space' :: Parser CommandSpace
139-
space' = subparser
140-
( command "list" list
141-
<> command "run" run
142-
)
143-
where
144-
list = info (ListS <$> listOpt <**> helper)
145-
( fullDesc
146-
<> progDesc "Compare benchmarks of graphs libraries"
147-
<> header "Help" )
148-
run = info ( (RunS <$> optional onlyOpt <*> optional notOnlyOpt <*> output <*> optional (some libOpt)) <**> helper)
128+
commandP :: ParserInfo Command
129+
commandP = info (semiOptional <**> helper)
149130
( fullDesc
150-
<> progDesc "list benchmarks"
131+
<> progDesc "Benchmark different graphs libraries"
151132
<> header "Help" )
152-
153-
commandSpace :: ParserInfo CommandSpace
154-
commandSpace = info ( semiOptional <**> helper)
155-
( fullDesc
156-
<> progDesc "Benchmark size of functions on different graphs libraries"
157-
<> header "Help")
158133
where
159-
semiOptional = pure (fromMaybe (RunS Nothing Nothing (Output True Nothing Ascii Nothing) Nothing)) <*> optional space'
134+
semiOptional = pure (fromMaybe (Run Nothing Nothing (Output True Nothing Ascii Nothing) Nothing False False [])) <*> optional command'
160135

161136
commandDataSize :: ParserInfo CommandDataSize
162137
commandDataSize = info ((RunD <$> graphsOpt) <**> helper)

bench/Space.hs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ tkChilds :: Grouped WeighResult -> Maybe [Grouped WeighResult]
163163
tkChilds = groupedToNamed >=> Just . snd
164164

165165
main :: IO ()
166-
main = execParser commandSpace >>= main'
166+
main = execParser commandP >>= main'
167167

168-
main' :: CommandSpace -> IO ()
169-
main' (ListS opt) = case opt of
168+
main' :: Command -> IO ()
169+
main' (List opt) = case opt of
170170
Benchs -> putStr $ unlines $ benchsNames Nothing Nothing
171171
Libs -> putStr $ unlines $ nub $ map fst listOfSuites
172-
main' (RunS only notonly flg libs) = do
172+
main' (Run only notonly flg libs _ _ _) = do
173173
printHeader defaultGr bN
174174
mainWeigh benchs (useResults flg (mapMaybe (\(n,Shadow s) -> either (\x -> Just (n,x)) (const Nothing) s ) filteredArr))
175175
where
@@ -179,12 +179,21 @@ main' (RunS only notonly flg libs) = do
179179
addCrea = if "creation" `elem` bN then (++ listOfCreation) else id
180180
filteredArr = filter (`isNameIn` bN) listOfSuites
181181

182-
benchsNames :: Maybe [String] -> Maybe [String] -> [String]
183-
benchsNames only notonly = nub (map (\(_,Shadow s) -> either fst name s) (maybe id (\e -> filter (\s -> not $ s `isNameIn` e)) notonly $ maybe id (\e -> filter (`isNameIn` e)) only listOfSuites)) ++ listOfCreation'
182+
benchsNames :: Maybe Option -> Maybe [String] -> [String]
183+
benchsNames only notonly = useNotOnly $ useOnly extractedNames
184184
where
185-
listOfCreation' = case only of
186-
Nothing -> ["creation"]
187-
Just e -> [ "creation" | "creation" `elem` e]
185+
extractedNames = "creation" : map (\(_,Shadow s) -> either fst name s) listOfSuites
186+
useOnly = case only of
187+
Nothing -> id
188+
(Just (Only lst)) -> filter (`elem` lst)
189+
(Just (Part one' two)) -> \as ->
190+
let one = one' + 1
191+
per = length as `div` two
192+
f = if one' + 1 == two then id else take (one*per)
193+
in drop ((one-1)*per) $ f as
194+
useNotOnly = case notonly of
195+
Nothing -> id
196+
(Just lst) -> filter (`notElem` lst)
188197

189198
isNameIn :: (a,ShadowedS) -> [String] -> Bool
190199
isNameIn (_,Shadow s) e = either fst name s `elem` e

bench/Time.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ benchmarkWithoutOutput bm = do
194194
defaultConfig' = defaultConfig {verbosity = Quiet, timeLimit = 10}
195195

196196
main :: IO ()
197-
main = execParser commandTime >>= main'
197+
main = execParser commandP >>= main'
198198

199-
main' :: CommandTime -> IO ()
199+
main' :: Command -> IO ()
200200
main' opts
201201
= case opts of
202202
List listOpt -> case listOpt of

0 commit comments

Comments
 (0)