1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
module Test.Benchmark.Goodies
( showF2,
benchInputsResultsAsTable, benchResultsAsTable, toTableRow,
PlotStyle(..), plotResults
)
where
import Data.List ( intercalate )
import System.FilePath ( dropExtension, takeExtension )
import System.Process ( system )
showF2 :: Float -> String
showF2 x = let (xs,ys) = break (=='.') (show x)
in if null ys then xs ++ ".00"
else xs ++ "." ++ take 2 (tail ys ++ repeat '0')
benchInputsResultsAsTable :: (String,String) -> [(String,String)] -> String
benchInputsResultsAsTable (ilabel,rlabel) xs =
"\\begin{tabular}{|l|" ++ concat (take (length xs) (repeat "c|")) ++ "}\n" ++
"\\hline\n" ++
toTableRow (ilabel : map (\ (n,_) -> n) xs) ++
toTableRow (rlabel : map (\ (_,t) -> t) xs) ++
"\\hline\n\\end{tabular}\n"
benchResultsAsTable :: [String] -> [[String]] -> String
benchResultsAsTable colnames xs =
"\\begin{tabular}{|" ++ concat (take (length colnames) (repeat "r|")) ++ "}\n" ++
"\\hline\n" ++
toTableRow colnames ++
"\\hline\n" ++
concatMap toTableRow xs ++
"\\hline\n\\end{tabular}\n"
toTableRow :: [String] -> String
toTableRow xs = intercalate " & " xs ++" \\\\\n"
data PlotStyle = Lines
| Histogram
| Title String
| XLabel String
| YLabel String
| XTicsRotate Int
deriving Eq
plotStyle2GP :: PlotStyle -> String
plotStyle2GP Lines = "set style data linespoints\n" ++
"set key right bottom"
plotStyle2GP Histogram = "set style histogram clustered\n" ++
"set style data histograms"
plotStyle2GP (Title s) = "set title \"" ++ s ++ "\""
plotStyle2GP (XLabel s) = "set xlabel \"" ++ s ++ "\""
plotStyle2GP (YLabel s) = "set ylabel \"" ++ s ++ "\""
plotStyle2GP (XTicsRotate a) = "set xtics rotate by " ++ showInt a
showInt :: Int -> String
showInt i = if i<0 then '-' : show (-i) else show i
plotResults :: (Show a, Show b) =>
String -> [PlotStyle] -> [(String,[(a,b)])] -> IO ()
plotResults outfile pstyles titleddata = do
let pname = dropExtension outfile
outsuffix = takeExtension outfile
plotfileprefix = pname ++ "_"
scriptfile = pname ++ ".gpscript"
terminalset = case outsuffix of
".pdf" -> "set terminal pdf enhanced"
".jpg" -> "set terminal jpeg nocrop enhanced"
_ -> error $ "plotResults: unsupported out file format: " ++ outsuffix
titleddatafiles <- mapM (writeDataFile plotfileprefix) (zip [1..] titleddata)
writeFile scriptfile $ unlines $
[terminalset
,"set output '" ++ outfile ++ "'"
,"set tics nomirror"
,"set style fill solid border"] ++
map plotStyle2GP pstyles ++
["plot " ++ intercalate " , " (map plotCmd titleddatafiles)]
system $ "gnuplot " ++ scriptfile
putStrLn $ "Data plotted to '" ++ outfile ++ "'"
where
plotCmd (title,datfile) =
"\"" ++ datfile ++ "\" " ++
(if Histogram `elem` pstyles then "using 2:xtic(1) " else "") ++
(if null title then "notitle" else "title \"" ++ title ++ "\"")
writeDataFile :: (Show a, Show c, Show d) =>
String -> (a,(b,[(c,d)])) -> IO (b,String)
writeDataFile fileprefix (n,(title,bdata)) = do
let datafilename = fileprefix ++ show n ++ ".dat"
writeFile datafilename
(unlines (map (\ (x,y) -> show x ++ "\t" ++ show y) bdata))
return (title,datafilename)
test1 :: IO ()
test1 =
plotResults "xxx.jpg"
[Lines, Title "nrev run times",
XLabel "list length", YLabel "run time (seconds)"]
[data1,data2]
test2 :: IO ()
test2 =
plotResults "xxx.pdf"
[Histogram, Title "nrev run times",
XLabel " ",
XTicsRotate (-45),
YLabel "run time (seconds)"]
[data1,data2]
data1 :: (String, [(Int, Float)])
data1 = ("pakcs",
[(500,9.666666666666668e-2)
,(1000,0.3433333333333333)
,(1500,0.8533333333333334)
,(2000,1.6899999999999995)
,(2500,3.0066666666666664)
])
data2 :: (String, [(Int, Float)])
data2 = ("kics2",
[(500,0.0)
,(1000,1.0e-2)
,(1500,2.0e-2)
,(2000,3.0e-2)
,(2500,5.666666666666666e-2)
,(3000,8.333333333333333e-2)
,(3500,0.12)
,(4000,0.17)
,(4500,0.22)
,(5000,0.28)
,(5500,0.36000000000000004)
,(6000,0.44)
,(6500,0.53)
])
|