Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 496 lines (413 sloc) 17.955 kb
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
1 {-# LANGUAGE GADTs #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Criterion.ScalingBenchmark
5 -- Copyright : Simon Meier
6 -- License : BSD3-style (see LICENSE)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
7 --
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
8 -- Maintainer : Simon Meier <iridcode@gmail.com>
9 -- Stability : experimental
10 -- Portability : GHC
11 --
12 -- Measure the scaling behaviour of a benchmarkable function.
13 --
14 -----------------------------------------------------------------------------
15
16 module Criterion.ScalingBenchmark where
17
18 import Prelude hiding (lines)
19
566271db »
2010-10-17 refactored scaling comparison infrastructure
20 import Data.Function (on)
cacfe118 »
2010-11-10 extended options to allow for non-log plots
21 import Data.List (unfoldr, group, transpose, sortBy, intersperse)
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
22 import Data.Word (Word8)
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
23 import Data.Monoid
24 import Data.Int (Int64)
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
25
566271db »
2010-10-17 refactored scaling comparison infrastructure
26 import qualified Data.Vector.Generic as V
27
a7bbf4aa »
2010-11-04 renamed 'Text.Blaze' to 'Blaze.ByteString'
28 import Blaze.ByteString.Builder
29 import Blaze.ByteString.Builder.Internal
2be004a4 »
2010-10-16 first scaling benchmark plotting working
30
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
31 import qualified Data.Binary.Builder as B
32
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
33 import Data.Maybe
34 import Data.Accessor
35 import Data.Colour
36 import Data.Colour.Names
cda1e138 »
2010-10-31 implemented plotting to files
37 import Data.Char (isSpace, toLower)
38
39 import qualified Data.ByteString as S
40 import qualified Data.ByteString.Lazy as L
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
41
42 import Graphics.Rendering.Chart
43 import Graphics.Rendering.Chart.Grid
44 import Graphics.Rendering.Chart.Gtk
45
46 import Criterion
47 import Criterion.Environment
48 import Criterion.Monad
49 import Criterion.Types
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
50 import Criterion.Config hiding (Plot)
566271db »
2010-10-17 refactored scaling comparison infrastructure
51 import Criterion.Measurement (secs)
892be358 »
2010-10-17 also report number of outliers per test
52 import Criterion.Analysis (countOutliers, classifyOutliers)
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
53
2be004a4 »
2010-10-16 first scaling benchmark plotting working
54 import Control.Arrow (first, second)
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
55 import Control.Monad
56 import Control.Monad.Trans
57 import Control.Monad.Trans.Reader
58
59 import Statistics.Types
2be004a4 »
2010-10-16 first scaling benchmark plotting working
60 import Statistics.Sample
e8b11e54 »
2013-03-11 Remove trailing whitespace.
61 import Statistics.Quantile as Statistics
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
62 import Statistics.Function as Statistics
2be004a4 »
2010-10-16 first scaling benchmark plotting working
63
cda1e138 »
2010-10-31 implemented plotting to files
64 import System.FilePath
65
66 import Text.Printf (printf)
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
67
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
68 import Codec.Compression.GZip
2be004a4 »
2010-10-16 first scaling benchmark plotting working
69
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
70 import qualified System.Random as R
8fea44c0 »
2010-10-16 plotting of packing [Word8] works
71
2be004a4 »
2010-10-16 first scaling benchmark plotting working
72 -- Main function
73 ----------------
74
75 main :: IO ()
76 main = do
77 let config = defaultConfig
78 env <- withConfig config measureEnvironment
a8abdfbd »
2010-10-31 tuned plotting parameters
79 mapM_ (runAndPlot config env)
cacfe118 »
2010-11-10 extended options to allow for non-log plots
80 [ (compressComparison, defaultPlotConfig { pcLogYAxis = False })
81 , (packComparison, defaultPlotConfig)
82 , (zoomedPackComparison, defaultPlotConfig)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
83 ]
2be004a4 »
2010-10-16 first scaling benchmark plotting working
84 where
cacfe118 »
2010-11-10 extended options to allow for non-log plots
85 runAndPlot config env (sc, plotConfig) = do
cda1e138 »
2010-10-31 implemented plotting to files
86 sc' <- withConfig config $ runScalingComparison env sc
cacfe118 »
2010-11-10 extended options to allow for non-log plots
87 mkPlots sc' plotConfig
4ece6e71 »
2010-11-06 finished scaling benchmark generation
88
cacfe118 »
2010-11-10 extended options to allow for non-log plots
89 mkPlots sc plotConfig = sequence_
e8b11e54 »
2013-03-11 Remove trailing whitespace.
90 [ plotScalingComparison outType
cacfe118 »
2010-11-10 extended options to allow for non-log plots
91 (plotConfig {pcBoxPlot = doBoxPlot}) conv sc
4ece6e71 »
2010-11-06 finished scaling benchmark generation
92 | outType <- outTypes PDF ++ outTypes PNG,
cacfe118 »
2010-11-10 extended options to allow for non-log plots
93 doBoxPlot <- [True, False]
e8b11e54 »
2013-03-11 Remove trailing whitespace.
94 ]
4ece6e71 »
2010-11-06 finished scaling benchmark generation
95 where
96 conv = fromIntegral :: Int -> Double
97 outTypes f = map (uncurry f) [(640,480),(800,600),(1280,1024)]
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
98
99 -- | Comparison of different implementations of packing [Word8].
a8abdfbd »
2010-10-31 tuned plotting parameters
100 packComparison, zoomedPackComparison :: ScalingComparison Int
e8b11e54 »
2013-03-11 Remove trailing whitespace.
101 (packComparison, zoomedPackComparison) =
a8abdfbd »
2010-10-31 tuned plotting parameters
102 ( cmp "Packing [Word8]" broadVs (bsFaster ++ bsSlower)
103 , cmp "Packing short [Word8] lists" zoomedVs (bsFaster)
104 )
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
105 where
a8abdfbd »
2010-10-31 tuned plotting parameters
106 cmp name = compareBenchmarks name "bytes"
107
e8b11e54 »
2013-03-11 Remove trailing whitespace.
108 bsFaster =
a8abdfbd »
2010-10-31 tuned plotting parameters
109 [ ScalingBenchmark "S.pack" (\x-> whnf S.pack (take x word8s))
110 , ScalingBenchmark "packLazy" (\x-> whnf (L.length . packLazy) (take x word8s))
111 , ScalingBenchmark "packStrict" (\x-> whnf packStrict (take x word8s))
112 ]
113
e8b11e54 »
2013-03-11 Remove trailing whitespace.
114 bsSlower =
a8abdfbd »
2010-10-31 tuned plotting parameters
115 [ ScalingBenchmark "L.pack" (\x-> whnf (L.length . L.pack) (take x word8s))
116 , ScalingBenchmark "declPackLazy" (\x-> whnf (L.length . declPackLazy) (take x word8s))
117 , ScalingBenchmark "Binary.declPackLazy" (\x-> whnf (L.length . binaryDeclPackLazy) (take x word8s))
118 ]
e8b11e54 »
2013-03-11 Remove trailing whitespace.
119
a8abdfbd »
2010-10-31 tuned plotting parameters
120 mkLogVs :: Double -> Double -> [Int]
e8b11e54 »
2013-03-11 Remove trailing whitespace.
121 mkLogVs factor upperBound =
122 map head . group . map round . takeWhile (<= upperBound) $
a8abdfbd »
2010-10-31 tuned plotting parameters
123 iterate (*factor) 1
124
125 broadVs = mkLogVs 1.5 (200 * 1024)
f5f573c4 »
2010-11-04 changed parameter for one plot
126 zoomedVs = mkLogVs 1.1 256
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
127
4ece6e71 »
2010-11-06 finished scaling benchmark generation
128 byteStringPackLazy :: [Word8] -> L.ByteString
129 byteStringPackLazy = L.pack
130
131 byteStringPackStrict :: [Word8] -> S.ByteString
132 byteStringPackStrict = S.pack
133
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
134 packLazy :: [Word8] -> L.ByteString
135 packLazy = toLazyByteString . fromWord8s
136
137 packStrict :: [Word8] -> S.ByteString
138 packStrict = toByteString . fromWord8s
139
a8abdfbd »
2010-10-31 tuned plotting parameters
140 declPackLazy :: [Word8] -> L.ByteString
141 declPackLazy = toLazyByteString . mconcat . map fromWord8
142
143 binaryDeclPackLazy :: [Word8] -> L.ByteString
144 binaryDeclPackLazy = B.toLazyByteString . mconcat . map B.singleton
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
145
146 word8s :: [Word8]
147 word8s = cycle [0..]
148 {-# NOINLINE word8s #-}
149
150
151 chunk :: Int -> [a] -> [[a]]
152 chunk size xs = c : case xs' of [] -> []; _ -> chunk size xs'
153 where
154 (c, xs') = splitAt size xs
155
156 -- | Compare compressing a chunked sequence of bytes with and without
157 -- compaction on redundant and random data.
158 compressComparison :: ScalingComparison Int
159 compressComparison = compareBenchmarks ("Compressing "++show kb++"kb of data") "chunk size in bytes" vs $
5a0a6382 »
2010-11-10 ignore generated .pdf and .png files
160 {-
a8abdfbd »
2010-10-31 tuned plotting parameters
161 [ ScalingBenchmark "rnd. data / direct" (whnf compressDirectly . randomByteStrings)
162 , ScalingBenchmark "rnd. data / with compaction" (whnf compressCompacted . randomByteStrings)
163 , ScalingBenchmark "red. data / direct" (whnf compressDirectly . redundantByteStrings)
164 , ScalingBenchmark "red. data / with compaction" (whnf compressCompacted . redundantByteStrings)
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
165 ]
5a0a6382 »
2010-11-10 ignore generated .pdf and .png files
166 -}
167 [ ScalingBenchmark "direct" (whnf compressDirectly . redundantByteStrings)
168 , ScalingBenchmark "with compaction" (whnf compressCompacted . redundantByteStrings)
169 , ScalingBenchmark "compaction only" (whnf compaction . redundantByteStrings)
170 ]
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
171 where
172 kb = 200
173 n = kb * 1024
174
175 vs :: [Int]
176 vs = takeWhile (<= 100000) $ iterate (2*) 1
177
e8b11e54 »
2013-03-11 Remove trailing whitespace.
178 -- randomWord8s = map fromIntegral . take n $ unfoldr (Just . R.next) (R.mkStdGen 666)
5a0a6382 »
2010-11-10 ignore generated .pdf and .png files
179 -- randomByteStrings c = L.fromChunks . map S.pack . chunk c $ randomWord8s
180 -- {-# NOINLINE randomByteStrings #-}
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
181
182 redundantWord8s = take n $ cycle [0..]
183 redundantByteStrings c = L.fromChunks . map S.pack . chunk c $ redundantWord8s
184 {-# NOINLINE redundantByteStrings #-}
185
186 compressDirectly :: L.ByteString -> Int64
187 compressDirectly = L.length . compress
188
189 compressCompacted :: L.ByteString -> Int64
e8b11e54 »
2013-03-11 Remove trailing whitespace.
190 compressCompacted =
b927cf65 »
2010-10-24 implemented comparision of compression times with/without compaction
191 L.length . compress . toLazyByteString . fromLazyByteString
192
5a0a6382 »
2010-11-10 ignore generated .pdf and .png files
193 compaction :: L.ByteString -> Int64
194 compaction = L.length . toLazyByteString . fromLazyByteString
195
2be004a4 »
2010-10-16 first scaling benchmark plotting working
196
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
197 -- BoxPlots
198 -----------
e8b11e54 »
2013-03-11 Remove trailing whitespace.
199
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
200 data BoxPlot = BoxPlot
201 { bpMean :: Double
202 , bpHighSevereOutliers :: Sample
203 , bpHighMildOutliers :: Sample
204 , bpHighWhisker :: Double
205 , bpHighQuartile :: Double
206 , bpMedian :: Double
207 , bpLowQuartile :: Double
208 , bpLowWhisker :: Double
209 , bpLowMildOutliers :: Sample
210 , bpLowSevereOutliers :: Sample
211 }
212
213 boxPlot :: Sample -> BoxPlot
214 boxPlot sa = BoxPlot
215 { bpMean = mean ssa
216 , bpHighSevereOutliers = V.filter (hiS <) ssa
217 , bpHighMildOutliers = V.filter (\x -> hiM < x && x <= hiS) ssa
218 , bpHighWhisker = fromMaybe hiM $ V.find (hiM >=) (V.reverse ssa)
219 , bpHighQuartile = q3
220 , bpMedian = Statistics.weightedAvg 2 4 ssa
221 , bpLowQuartile = q1
222 , bpLowWhisker = fromMaybe loM $ V.find (loM <=) ssa
223 , bpLowMildOutliers = V.filter (\x -> loS <= x && x < loM) ssa
224 , bpLowSevereOutliers = V.filter (< loS) ssa
225 }
226 where
227 ssa = Statistics.sort sa
228 loS = q1 - (iqr * 3)
229 loM = q1 - (iqr * 1.5)
230 hiM = q3 + (iqr * 1.5)
231 hiS = q3 + (iqr * 3)
232 q1 = Statistics.weightedAvg 1 4 ssa
233 q3 = Statistics.weightedAvg 3 4 ssa
234 iqr = q3 - q1
235
236 -- | Compute the k-th percentile of a sample.
237 percentile :: Int -> Sample -> Double
238 percentile k = Statistics.weightedAvg k 100
2be004a4 »
2010-10-16 first scaling benchmark plotting working
239
240 -- Scaling Benchmark Infrastructure
241 -----------------------------------
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
242
243 -- | A scaling benchmark denotes a named benchmark constructor, which can be
244 -- used to investigate the scaling behaviour of a 'Benchmarkable' function.
566271db »
2010-10-17 refactored scaling comparison infrastructure
245 data ScalingBenchmark a where
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
246 ScalingBenchmark :: (Benchmarkable b)
566271db »
2010-10-17 refactored scaling comparison infrastructure
247 => String -- ^ Benchmark name
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
248 -> (a -> b) -- ^ Benchmark constructor
566271db »
2010-10-17 refactored scaling comparison infrastructure
249 -> ScalingBenchmark a -- ^ Scaling benchmark
250
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
251 -- | Extract the name of a 'ScalingBenchmark'.
252 scalingBenchmarkName :: ScalingBenchmark a -> String
253 scalingBenchmarkName (ScalingBenchmark name _) = name
254
566271db »
2010-10-17 refactored scaling comparison infrastructure
255 -- | A comparison of several benchmarks on a common set of test points.
256 data ScalingComparison a = ScalingComparison
257 { scName :: String
258 , scTestUnit :: String
259 , scTestValues :: [a] -- INV: non-empty
260 , scBenchmarks :: [ScalingBenchmark a] -- INV: non-empty
261 , scMeasurements :: [[Sample]] -- measurements: benchmarks * test points;
262 -- [] iff the benchmarks haven't been run yet
263 }
264
265 -- | Compare several benchmarks on a set of test values.
266 compareBenchmarks :: String -- ^ Name of comparison.
267 -> String -- ^ Unit of test values.
268 -> [a] -- ^ Test values.
269 -> [ScalingBenchmark a] -- ^ Benchmarks to compare.
270 -> ScalingComparison a -- ^ Resulting scaling comparison.
e8b11e54 »
2013-03-11 Remove trailing whitespace.
271 compareBenchmarks name unit vs bs =
566271db »
2010-10-17 refactored scaling comparison infrastructure
272 ScalingComparison name unit vs bs []
273
274 -- | Annotate the measurements stored in a 'ScalingComparison'.
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
275 annotateMeasurements :: (a -> b)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
276 -> ScalingComparison a
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
277 -> [(String, [(b,Sample)])]
278 annotateMeasurements f sc =
e8b11e54 »
2013-03-11 Remove trailing whitespace.
279 zip (map scalingBenchmarkName $ scBenchmarks sc)
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
280 (map (zip (map f $ scTestValues sc)) (scMeasurements sc))
566271db »
2010-10-17 refactored scaling comparison infrastructure
281
282 -- | Run a 'ScalingComparison'.
283 runScalingComparison :: Show a
284 => Environment -- ^ Criterion environment.
285 -> ScalingComparison a -- ^ Comparison to run (may or may not contain any measurements already).
286 -> Criterion (ScalingComparison a) -- ^ Comparison with 'scMeasurements' field set to new measurements.
287 runScalingComparison env sc = do
288 samples <- mapM runBenchmarks $ scTestValues sc
289 return $ sc { scMeasurements = transpose samples }
290 where
291
292 runBenchmarks x = do
293 let testPointStr = show x ++ " " ++ scTestUnit sc
294 liftIO $ putStrLn $ ""
295 liftIO $ putStrLn $ "running benchmarks for " ++ testPointStr
e8b11e54 »
2013-03-11 Remove trailing whitespace.
296 samples <- sequence
297 [ ((,) name) `liftM` runBenchmark env (mkBench x)
566271db »
2010-10-17 refactored scaling comparison infrastructure
298 | ScalingBenchmark name mkBench <- scBenchmarks sc ]
299 liftIO $ putStrLn $ ""
300 liftIO $ putStrLn $ "ranking for " ++ testPointStr
301 liftIO $ quickAnalysis samples
302 return $ map snd samples
303
304 quickAnalysis samples = do
305 let indent = length (show $ length samples + 1) + 2
306 extent = maximum (map (length . fst) samples) + 2
e8b11e54 »
2013-03-11 Remove trailing whitespace.
307 mapM_ (printStatistics indent extent)
892be358 »
2010-10-17 also report number of outliers per test
308 (zip [1..] $ sortBy (compare `on` (mean . snd)) samples)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
309
566271db »
2010-10-17 refactored scaling comparison infrastructure
310 printStatistics :: Int -> Int -> (Int, (String, Sample)) -> IO ()
311 printStatistics indent extent (i, (info, sample)) = putStrLn $
312 rightAlign indent (show i) ++ ". " ++
313 leftAlign extent (info ++ ":") ++
e8b11e54 »
2013-03-11 Remove trailing whitespace.
314 "mean " ++ secs (mean sample) ++
315 " (2p " ++ secs p2 ++
566271db »
2010-10-17 refactored scaling comparison infrastructure
316 ", 98p " ++ secs p98 ++
f8d99541 »
2010-10-17 more readable name for outliers
317 ", out " ++ rightAlign 2 (show outliers) ++
566271db »
2010-10-17 refactored scaling comparison infrastructure
318 ")"
319 where
320 -- percentiles
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
321 p2 = percentile 2 sample
322 p98 = percentile 98 sample
892be358 »
2010-10-17 also report number of outliers per test
323 -- outliers
324 outliers = countOutliers . classifyOutliers $ sample
566271db »
2010-10-17 refactored scaling comparison infrastructure
325
326 rightAlign n cs = take (n - length cs) (repeat ' ') ++ cs
327 leftAlign n cs = cs ++ take (n - length cs) (repeat ' ')
328
cacfe118 »
2010-11-10 extended options to allow for non-log plots
329 data PlotConfig = PlotConfig {
330 pcBoxPlot :: Bool
331 , pcLogYAxis :: Bool
332 , pcLogXAxis :: Bool
e8b11e54 »
2013-03-11 Remove trailing whitespace.
333 }
cacfe118 »
2010-11-10 extended options to allow for non-log plots
334 deriving( Eq, Ord, Show )
335
336 defaultPlotConfig :: PlotConfig
337 defaultPlotConfig = PlotConfig True True True
338
339 prettyPlotConfig (PlotConfig boxPlot logY logX) =
340 concat $ intersperse "," $ msum
341 [f boxPlot "boxplot", f logY "log-y", f logX "log-x"]
342 where
343 f b info = if b then return info else mzero
cda1e138 »
2010-10-31 implemented plotting to files
344
345 -- | Plot a scaling comparison.
e8b11e54 »
2013-03-11 Remove trailing whitespace.
346 plotScalingComparison :: (PlotValue b, RealFloat b)
cda1e138 »
2010-10-31 implemented plotting to files
347 => PlotOutput -- ^ Output format.
cacfe118 »
2010-11-10 extended options to allow for non-log plots
348 -> PlotConfig -- ^ Plot configuration.
cda1e138 »
2010-10-31 implemented plotting to files
349 -> (a -> b) -- ^ Test point conversion function.
350 -> ScalingComparison a -- ^ Comparison to plot.
351 -> IO ()
352
cacfe118 »
2010-11-10 extended options to allow for non-log plots
353 plotScalingComparison output config conv sc =
354 renderableToFile $ renderScalingComparison config conv sc
4ece6e71 »
2010-11-06 finished scaling benchmark generation
355 where
356 renderableToFile = case output of
357 PDF x y -> \r -> renderableToPDFFile r x y (mkName "pdf" x y)
358 PNG x y -> \r -> renderableToPNGFile r x y (mkName "png" x y)
359 SVG x y -> \r -> renderableToSVGFile r x y (mkName "svg" x y)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
360 Window x y -> \r -> renderableToWindow r x y
cda1e138 »
2010-10-31 implemented plotting to files
361
e8b11e54 »
2013-03-11 Remove trailing whitespace.
362 mkName fileType x y = mangle $
4ece6e71 »
2010-11-06 finished scaling benchmark generation
363 printf "%s scaling %s%dx%d.%s" (scName sc) plotType x y fileType
cda1e138 »
2010-10-31 implemented plotting to files
364
cacfe118 »
2010-11-10 extended options to allow for non-log plots
365 plotType = case prettyPlotConfig config of
366 "" -> ""
367 info -> "("++info++")"
cda1e138 »
2010-10-31 implemented plotting to files
368
4ece6e71 »
2010-11-06 finished scaling benchmark generation
369 -- plotScalingComparison (PNG x y) doBoxplot conv sc =
370 -- renderableToPNGFile (renderScalingComparison doBoxplot conv sc) x y
371 -- (mangle $ printf "%s scaling %dx%d.png" (scName sc) x y)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
372 --
4ece6e71 »
2010-11-06 finished scaling benchmark generation
373 -- plotScalingComparison (SVG x y) doBoxplot conv sc =
374 -- renderableToSVGFile (renderScalingComparison doBoxplot conv sc) x y
375 -- (mangle $ printf "%s scaling %dx%d.svg" (scName sc) x y)
e8b11e54 »
2013-03-11 Remove trailing whitespace.
376 --
4ece6e71 »
2010-11-06 finished scaling benchmark generation
377 -- plotScalingComparison (Window x y) doBoxplot conv sc =
378 -- renderableToWindow (renderScalingComparison doBoxplot conv sc) x y
e8b11e54 »
2013-03-11 Remove trailing whitespace.
379 --
cda1e138 »
2010-10-31 implemented plotting to files
380
381 -- | Render a scaling comparison using an adaption of the boxplot technique to
382 -- lineplots.
e8b11e54 »
2013-03-11 Remove trailing whitespace.
383 renderScalingComparison :: (PlotValue b, RealFloat b)
cacfe118 »
2010-11-10 extended options to allow for non-log plots
384 => PlotConfig -> (a -> b) -> ScalingComparison a -> Renderable ()
e8b11e54 »
2013-03-11 Remove trailing whitespace.
385 renderScalingComparison config f sc =
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
386 toRenderable $
387 layout1_plots ^= plots $
388 layout1_title ^= scName sc $
cacfe118 »
2010-11-10 extended options to allow for non-log plots
389 layout1_bottom_axis ^= mkAxis pcLogXAxis (scTestUnit sc) $
390 layout1_right_axis ^= mkAxis pcLogYAxis "seconds" $
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
391 defaultLayout1
392 where
cacfe118 »
2010-11-10 extended options to allow for non-log plots
393 mkAxis proj | proj config = mkLogAxis
394 | otherwise = mkLinearAxis
395 plotFunction | pcBoxPlot config = boxplotAnnotatedSamples
396 | otherwise = plotAnnotatedSamples
4ece6e71 »
2010-11-06 finished scaling benchmark generation
397 plots = concat $ zipWith plotFunction
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
398 (map opaque $ colorPalette)
399 (annotateMeasurements f sc)
400
401
402
4ece6e71 »
2010-11-06 finished scaling benchmark generation
403 -- | Plot the means of the annotated samples
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
404 --
e8b11e54 »
2013-03-11 Remove trailing whitespace.
405 plotAnnotatedSamples :: AlphaColour Double
406 -> (String, [(a,Sample)])
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
407 -> [Either (Plot a Double) (Plot a Double)]
408 plotAnnotatedSamples colour (name, points) =
4ece6e71 »
2010-11-06 finished scaling benchmark generation
409 return . Right $ line (solidLine 1) 1 mean
410 where
411 line style trans proj = toPlot $ plotLine name
412 (solidLine 1 $ dissolve trans colour)
413 (map (second proj) points)
414
415 -- | Plot the annotated samples as a boxplot. This should be used to check the
416 -- soundness of the measured results.
417 --
e8b11e54 »
2013-03-11 Remove trailing whitespace.
418 boxplotAnnotatedSamples :: AlphaColour Double
419 -> (String, [(a,Sample)])
4ece6e71 »
2010-11-06 finished scaling benchmark generation
420 -> [Either (Plot a Double) (Plot a Double)]
421 boxplotAnnotatedSamples colour (name, points) =
25ac7fe0 »
2010-10-24 fixed legend of line-boxplots
422 map (Right . noLegend . uncurry (line (solidLine 1)))
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
423 [ (0.2, bpLowWhisker)
424 , (0.4, bpLowQuartile)
425 , (0.4, bpHighQuartile)
426 , (0.2, bpHighWhisker)
6bb0cf24 »
2010-10-24 plotting outliers works
427 ] ++
25ac7fe0 »
2010-10-24 fixed legend of line-boxplots
428 [ Right $ line (solidLine 1) 0.9 bpMedian] ++
429 map (Right . noLegend)
6bb0cf24 »
2010-10-24 plotting outliers works
430 [ toPlot $ plotPoints name meanStyle (map (second bpMean) points')
431 , outliers severeOutStyle bpHighSevereOutliers
432 , outliers severeOutStyle bpLowSevereOutliers
433 , outliers mildOutStyle bpHighMildOutliers
434 , outliers mildOutStyle bpLowMildOutliers
e8b11e54 »
2013-03-11 Remove trailing whitespace.
435 ]
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
436 where
437 points' = map (second boxPlot) points
e8b11e54 »
2013-03-11 Remove trailing whitespace.
438
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
439 line style trans proj = toPlot $ plotLine name
440 (solidLine 1 $ dissolve trans colour)
441 (map (second proj) points')
442
6bb0cf24 »
2010-10-24 plotting outliers works
443 outliers style proj = toPlot $ plotPoints name style
444 (concat [zip (repeat x) (V.toList $ proj bp) | (x, bp) <- points'])
445
446 severeOutStyle = filledCircles 2 (dissolve 0.4 colour)
447 mildOutStyle = hollowCircles 2 1 (dissolve 0.4 colour)
448 meanStyle = exes 3 1 colour
449
450
25ac7fe0 »
2010-10-24 fixed legend of line-boxplots
451 noLegend :: Plot x y -> Plot x y
452 noLegend = plot_legend ^= []
453
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
454 -- | Plot a single named line using the given line style.
455 plotLine :: String -> CairoLineStyle -> [(a,b)] -> PlotLines a b
e8b11e54 »
2013-03-11 Remove trailing whitespace.
456 plotLine name style points =
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
457 plot_lines_title ^= name $
458 plot_lines_style ^= style $
e8b11e54 »
2013-03-11 Remove trailing whitespace.
459 plot_lines_values ^= [points] $
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
460 defaultPlotLines
461
6bb0cf24 »
2010-10-24 plotting outliers works
462 -- | Plot a single named line using the given line style.
463 plotPoints :: String -> CairoPointStyle -> [(a,b)] -> PlotPoints a b
e8b11e54 »
2013-03-11 Remove trailing whitespace.
464 plotPoints name style points =
6bb0cf24 »
2010-10-24 plotting outliers works
465 plot_points_title ^= name $
466 plot_points_style ^= style $
e8b11e54 »
2013-03-11 Remove trailing whitespace.
467 plot_points_values ^= points $
6bb0cf24 »
2010-10-24 plotting outliers works
468 defaultPlotPoints
469
470
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
471 colorPalette :: [Colour Double]
472 colorPalette = [blue, green, red, cyan, magenta, yellow]
473
474 mkLinearAxis :: PlotValue x => String -> LayoutAxis x
475 mkLinearAxis name = laxis_title ^= name $ defaultLayoutAxis
476
477 mkLogAxis :: (RealFloat x, PlotValue x) => String -> LayoutAxis x
e8b11e54 »
2013-03-11 Remove trailing whitespace.
478 mkLogAxis name =
479 laxis_title ^= name $
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
480 laxis_generate ^= autoScaledLogAxis defaultLogAxis $
481 defaultLayoutAxis
482
e8b11e54 »
2013-03-11 Remove trailing whitespace.
483 -- Filehandling
cda1e138 »
2010-10-31 implemented plotting to files
484 ---------------
ad4b22c8 »
2010-10-22 combination of line plots with boxplotting technique is now working
485
566271db »
2010-10-17 refactored scaling comparison infrastructure
486
cda1e138 »
2010-10-31 implemented plotting to files
487 -- | Get rid of spaces and other potentially troublesome characters
488 -- from output.
489 --
490 -- Copied from: Criterion.Plot
491 mangle :: String -> FilePath
492 mangle = concatMap (replace ((==) '-' . head) "-")
493 . group
494 . map (replace isSpace '-' . replace (==pathSeparator) '-' . toLower)
495 where replace p r c | p c = r
496 | otherwise = c
7ba6097c »
2010-10-13 started implementing scaling benchmark infrastructure
497
Something went wrong with that request. Please try again.