Skip to content
Prev Previous commit
Next Next commit
decide chart height from dataset size, print dims
  • Loading branch information
clayrat committed Jun 8, 2023
commit 6a43d8af24ce8994ecbc499e0f479916a3aeff32
13 changes: 8 additions & 5 deletions scripts/plot-performance/app/Benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Prelude hiding (readFile, writeFile, filter, zip, lookup)
import Data.Ord (Down(..))
import Data.String (fromString)
import Data.List as L
import Data.Vector as V hiding (concat, null, (++), last, find)
import Data.Vector as V hiding (length, concat, null, (++), last, find)
import Data.Map as M hiding (null)
import Data.ByteString.Char8 (unpack)
import Data.ByteString.Lazy.Char8 (readFile, writeFile)
Expand Down Expand Up @@ -61,6 +61,9 @@ data BenchmarkDataSet = BenchmarkDS
, added :: [(String, BData)]
} deriving stock (Eq, Ord, Show, Generic)

bdsLen :: BenchmarkDataSet -> Int
bdsLen (BenchmarkDS rs xs as) = length rs + length xs + length as

splitBenchmarks :: Vector Benchmark
-> Vector Benchmark
-> BenchmarkDataSet
Expand All @@ -81,16 +84,16 @@ hiBenchmarks :: Int -> BenchmarkDataSet -> BenchmarkDataSet
hiBenchmarks n (BenchmarkDS rs xs as) =
let rs' = L.take n $ sortOn (Down . fst . snd) rs
ys = sortOn (\(_, bt, at) -> fst at - fst bt) xs
ys' = L.take (n - L.length rs') ys
as' = L.take (n - (L.length rs' + L.length ys')) $ sortOn (Down . fst . snd) as
ys' = L.take (n - length rs') ys
as' = L.take (n - (length rs' + length ys')) $ sortOn (Down . fst . snd) as
in BenchmarkDS rs' ys' as'

loBenchmarks :: Int -> BenchmarkDataSet -> BenchmarkDataSet
loBenchmarks n (BenchmarkDS rs xs as) =
let as' = L.take n $ sortOn (fst . snd) as
ys = sortOn (\(_, bt, at) -> fst bt - fst at) xs
ys' = L.take (n - L.length as') ys
rs' = L.take (n - (L.length as' + L.length ys')) $ sortOn (fst . snd) rs
ys' = L.take (n - length as') ys
rs' = L.take (n - (length as' + length ys')) $ sortOn (fst . snd) rs
in BenchmarkDS rs' ys' as'

decouple :: BenchmarkDataSet -> Bool -> ([Benchmark], [Benchmark])
Expand Down
15 changes: 13 additions & 2 deletions scripts/plot-performance/app/Plot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,23 @@ diffData rev (BenchmarkDS rs xs as) =
, (LogValue v, printf "%0.2f" v)
, (LogValue 0, "") ] )) as

-- This is fitted to specific values above (font size etc)
heightHeuristic :: Int -> Double
heightHeuristic n | n < 10 = 8.0
| n < 28 = 9.0
| n < 65 = 10.0
| n < 138 = 11.0
| n < 283 = 12.0
| n < 577 = 13.0
| otherwise = 14.0

chartToFile :: Bool -> String -> BenchmarkDataSet -> FilePath -> IO ()
chartToFile rev title bds path =
do let wh = (2048.0, 2048.0)
do let len = bdsLen bds
let wh = (2048.0, 2.0 ** heightHeuristic len)
let fo = FileOptions wh SVG loadSansSerifFonts
let plot = chart rev title bds
let cb = render plot wh
putStrLn $ "Writing " ++ path
putStrLn $ printf "Writing %s (%d entries, %.0fx%.0f)" path len (fst wh) (snd wh)
_ <- cBackendToFile fo cb path
pure ()