Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
reflex-frp
GitHub Repository: reflex-frp/reflex-platform
Path: blob/develop/benchmarking/compareBenchmarkResults.hs
1 views
1
{-# LANGUAGE TemplateHaskell #-}
2
{-# LANGUAGE OverloadedStrings #-}
3
4
import Control.Arrow
5
import Control.Lens
6
import Data.Aeson
7
import Data.Aeson.TH
8
import Data.Align
9
import qualified Data.ByteString.Lazy as LBS
10
import Data.Either
11
import Data.Foldable
12
import qualified Data.Map as Map
13
import Data.Monoid
14
import qualified Data.Text as T
15
import qualified Data.Text.IO as T
16
import Data.Text (Text)
17
import Data.These
18
import System.Environment
19
import System.FilePath
20
21
data BenchmarkResult = BenchmarkResult
22
{ _benchmarkResult_framework :: Text
23
, _benchmarkResult_benchmark :: Text
24
, _benchmarkResult_type :: Text
25
, _benchmarkResult_min :: Double
26
, _benchmarkResult_max :: Double
27
, _benchmarkResult_mean :: Double
28
, _benchmarkResult_median :: Double
29
, _benchmarkResult_geometricMean :: Double
30
, _benchmarkResult_standardDeviation :: Double
31
, _benchmarkResult_values :: [Double]
32
}
33
deriving (Show, Read, Eq, Ord)
34
35
deriveJSON (defaultOptions { fieldLabelModifier = drop $ length ("_benchmarkResult_" :: String) }) ''BenchmarkResult
36
37
loadResult :: FilePath -> IO [BenchmarkResult]
38
loadResult p = either error id . eitherDecode <$> LBS.readFile p
39
40
main :: IO ()
41
main = do
42
[file1, file2] <- getArgs
43
results1 <- loadResult file1
44
results2 <- loadResult file2
45
let byFramework = Map.fromListWith (<>) . map (_benchmarkResult_framework &&& pure)
46
befores = byFramework results1
47
afters = byFramework results2
48
inters = Map.intersectionWith (,) befores afters
49
traverse_ T.putStrLn $ Map.mapWithKey table inters
50
51
table :: Text -> ([BenchmarkResult], [BenchmarkResult]) -> Text
52
table framework (before, after) =
53
let resultMap = Map.fromList . fmap (_benchmarkResult_benchmark &&& _benchmarkResult_geometricMean)
54
results1 = resultMap before
55
results2 = resultMap after
56
showMNum = maybe "?" (T.pack . show)
57
title = "### " <> framework
58
header = "| Benchmark | Before | After | Ratio |"
59
separator = "| --- | --- | --- | --- |"
60
formatLine (b, rs) =
61
let r1 = preview here rs
62
r2 = preview there rs
63
in "| " <> b <> " | " <> showMNum r1 <> " | " <> showMNum r2 <> " | " <> showMNum ((/) <$> r2 <*> r1) <> " |"
64
in
65
T.unlines $ title : header : separator : fmap formatLine (Map.toList $ align results1 results2)
66
67