Skip to content

Commit

Permalink
Added perf and fixed up readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyday567 committed Jul 21, 2023
1 parent 3dfc26b commit f99a20e
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 441 deletions.
16 changes: 16 additions & 0 deletions app/app.hs
@@ -0,0 +1,16 @@
-- |

module Main where

import Prelude
import Data.Bool
import Data.Foldable
import Box

data Teletype m a where
ReadTTY :: Teletype m String
WriteTTY :: String -> Teletype m ()

echo :: (Monad m, Eq a, Monoid a) => Box m a a -> m ()
echo = fuse (\x -> bool (pure (Just x)) (pure Nothing) (x == mempty))

88 changes: 88 additions & 0 deletions app/speed.hs
@@ -0,0 +1,88 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wno-unused-do-bind #-}

import Control.Applicative
import Control.Monad
import Data.List (intercalate)
import qualified Data.Map.Strict as Map
import Data.Semigroup
import Options.Applicative
import Perf
import Prelude
import Box

toListMTest :: Int -> IO [Int]
toListMTest n = toListM <$|> qListWith Unbounded [1..n]

pushListTest :: Int -> IO [Int]
pushListTest n = pushList <$|> (qListWith Unbounded [1..n])

Check warning on line 22 in app/speed.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in pushListTest in module Main: Redundant bracket ▫︎ Found: "pushList <$|> (qListWith Unbounded [1 .. n])" ▫︎ Perhaps: "pushList <$|> qListWith Unbounded [1 .. n]"

data TestType = TestToListM | TestQList | TestDefault deriving (Eq, Show)

parseTestType :: Parser TestType
parseTestType =
flag' TestToListM (long "toListM" <> help "test toListM speed")
<|> flag' TestQList (long "qList" <> help "test qList speed")
<|> pure TestDefault

data Options = Options
{ optionN :: Int,
optionL :: Int,
optionStatDType :: StatDType,
optionTestType :: TestType,
optionMeasureType :: MeasureType,
optionGolden :: Golden,
optionReportConfig :: ReportConfig,
optionRawStats :: Bool
}
deriving (Eq, Show)

options :: Parser Options
options =
Options
<$> option auto (value 1000 <> long "runs" <> short 'n' <> help "number of tests to perform")
<*> option auto (value 1000 <> long "length" <> short 'l' <> help "number of emits")
<*> parseStatD
<*> parseTestType
<*> parseMeasure
<*> parseGolden "golden"
<*> parseReportConfig defaultReportConfig
<*> switch (long "raw" <> short 'w' <> help "write raw statistics to file")

opts :: ParserInfo Options
opts =
info
(options <**> helper)
(fullDesc <> progDesc "box benchmarking" <> header "speed performance")

main :: IO ()
main = do
o <- execParser opts
let !n = optionN o
let !l = optionL o
let t = optionTestType o
let mt = optionMeasureType o
let gold = goldenFromOptions [show mt, show n, show l] (optionGolden o)
let w = optionRawStats o
let raw = "other/" <> intercalate "-" [show mt, show t, show n] <> ".map"
let cfg = optionReportConfig o

case t of
TestQList -> do
error "nyi"
TestToListM -> do
error "nyi"
TestDefault -> do
m <- fmap (fmap (measureFinalStat mt)) $
execPerfT (fmap (fmap average) $ measureDs mt n) $ do

Check warning on line 81 in app/speed.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in main in module Main: Use <$> ▫︎ Found: "fmap (fmap average) $ measureDs mt n" ▫︎ Perhaps: "fmap average <$> measureDs mt n"
_ <- fam "sum fold" (pure $ sum [1..l])
_ <- fam "toListM" (toListMTest l)
_ <- fam "pushList" (pushListTest l)

pure ()
when w (writeFile raw (show m))
report cfg gold (measureLabels mt) (Map.mapKeys (: []) (fmap (: []) m))
18 changes: 18 additions & 0 deletions box.cabal
Expand Up @@ -115,3 +115,21 @@ library
, stm ^>= 2.5.1
, text >=1.2 && < 2.1
, time >=1.9 && <1.13

executable box-speed
import: ghc2021-stanza
import: ghc-options-stanza
main-is: speed.hs
hs-source-dirs:
app
build-depends:
base >=4.7 && <5,
box,
perf ^>= 0.11,
containers,
optparse-applicative,
ghc-options:
-funbox-strict-fields
-rtsopts
-threaded
-O2
3 changes: 3 additions & 0 deletions cabal.project
@@ -1,3 +1,6 @@
packages:
box.cabal
../perf/perf.cabal

allow-newer: numhask-space:semigroupoids,
tdigest:semigroupoids
1 change: 1 addition & 0 deletions other/MeasureTime-1000-1000.perf
@@ -0,0 +1 @@
fromList [(["pushList","time"],1700193.684),(["sum fold","time"],1851.174),(["toListM","time"],1137498.997)]
1 change: 1 addition & 0 deletions other/TestDefault-1000-1000-MeasureTime.perf
@@ -0,0 +1 @@
fromList [(["pushList","time"],1639947.761),(["sum fold","time"],1818.752),(["toListM","time"],1123639.039)]

0 comments on commit f99a20e

Please sign in to comment.