packages feed

perf 0.10.0 → 0.10.1

raw patch · 8 files changed

+27/−39 lines, 8 filesdep −attoparsecdep −boxdep −box-csv

Dependencies removed: attoparsec, box, box-csv, chart-svg, optics-core

Files

app/explore.hs view
@@ -134,12 +134,12 @@   let gold' = optionGolden o   let gold =         case golden gold' of-          "other/golden.csv" ->+          "other/golden.perf" ->             gold'               { golden =                   "other/"                     <> intercalate "-" [show r, show n, show l, show mt]-                    <> ".csv"+                    <> ".perf"               }           _ -> gold'   let w = optionRawStats o
perf.cabal view
@@ -1,11 +1,10 @@ cabal-version:      2.4 name:               perf-version:            0.10.0+version:            0.10.1 synopsis:           Low-level run time measurement. description:-  A set of tools to accurately measure time performance of Haskell programs.-  perf aims to be lightweight by having minimal dependencies on standard libraries.-  See the Perf module for an example and full API documentation. +  A set of tools to measure performance of Haskell programs.+  See the Perf module for an example and full API documentation.  category:           project homepage:           https://github.com/tonyday567/perf#readme@@ -44,17 +43,12 @@    hs-source-dirs:     src   build-depends:-    , attoparsec            ^>=0.14     , base                  >=4.7    && <5-    , box                   ^>=0.8.1-    , box-csv               ^>=0.2-    , chart-svg             ^>=0.3     , containers            ^>=0.6     , deepseq               >=1.4.4  && <1.4.8     , formatn               ^>=0.2.1     , mtl                   ^>=2.2.2     , numhask-space         ^>=0.10-    , optics-core           ^>=0.4     , optparse-applicative  ^>=0.17     , rdtsc                 ^>=1.3     , recursion-schemes     ^>=5.2.2
src/Perf.hs view
@@ -6,25 +6,29 @@  -- | == Introduction ----- /perf/ provides high-resolution measurements of the runtime of Haskell functions. It does so by reading the RDTSC register (TSC stands for "time stamp counter"), which is present on all x86 CPUs since the Pentium architecture.+-- /perf/ provides tools for measuring the runtime performance of Haskell functions. It includes: ----- With /perf/ the user may measure both pure and effectful functions, as shown in the Example below. Every piece of code the user may want to profile is passed as an argument to the function, along with a text label (that will be displayed in the final summary) and the measurement function.+-- - time measurement via reading the RDTSC register (TSC stands for "time stamp counter"), which is present on all x86 CPUs since the Pentium architecture. For more details, see  https://en.wikipedia.org/wiki/Time_Stamp_Counter ----- 'PerfT' is a monad transformer designed to collect performance information.--- The transformer can be used to add performance measurent to existing code using 'Measure's.+-- - abstraction of what is a 'Measure' so that the library includes both space and time measurement with the same API. --+-- - 'PerfT' which is a monad transformer designed to add the collection of performance information to existing code. Running the code produces a tuple of the original computation results, and a Map of performance measurements that were specified. ----- Running the code produces a tuple of the original computation results, and a Map of performance measurements that were specified.  Indicative results:+-- - functionality to determine performance order, in 'Perf.BigO' ----- == Note on RDTSC+-- Usage examples can be found in app/perf-explore.hs and the project's readme.org. ----- Measuring program runtime with RDTSC comes with a set of caveats, such as portability issues, internal timer consistency in the case of multiprocessor architectures, and fluctuations due to power throttling. For more details, see : https://en.wikipedia.org/wiki/Time_Stamp_Counter module Perf   ( -- * re-exports+    -- | Various (fast loop) algorithms that have been used for testing perf functionality.     module Perf.Algos,+    -- | Low-level time performance 'Measure's counting 'Cycles'     module Perf.Time,+    -- | Order of complexity computations     module Perf.BigO,+    -- | Low-level space performance 'Measure's based on GHC's allocation statistics.     module Perf.Space,+    -- | Reporting, including 'Golden' file functionality.     module Perf.Report,     module Perf.Stats,     module Perf.Types,
src/Perf/Algos.hs view
@@ -291,7 +291,6 @@ sumFuse :: Int -> Int sumFuse x = sum [1 .. x] - -- | Fusion under polymorph sumFusePoly :: (Enum a, Num a) => a -> a sumFusePoly x = sum [1 .. x]@@ -388,6 +387,7 @@   where     b = 0     f _ xs = 1 + xs+ -- | foldr style with explicit const usage. lengthFoldrConst :: [a] -> Int lengthFoldrConst = foldr (const (1 +)) 0
src/Perf/Report.hs view
@@ -15,6 +15,7 @@     parseReportConfig,     writeResult,     readResult,+    CompareResult (..),     compareNote,     outercalate,     reportGolden,@@ -25,12 +26,8 @@   ) where -import Box hiding (value)-import qualified Box.Csv as Csv import Control.Monad-import qualified Data.Attoparsec.Text as A import Data.Bool-import Data.Either (fromRight) import Data.Foldable import Data.FormatN hiding (format) import qualified Data.List as List@@ -64,7 +61,6 @@     <|> pure h  -- | Levels of geometric difference in compared performance that triggers reporting.--- data CompareLevels = CompareLevels {errorLevel :: Double, warningLevel :: Double, improvedLevel :: Double} deriving (Eq, Show)  -- |@@ -103,17 +99,15 @@     <*> parseHeader (includeHeader c)     <*> parseCompareLevels (levels c) --- | Write results to file, in CSV format.+-- | Write results to file writeResult :: FilePath -> Map.Map [Text] Double -> IO ()-writeResult f m = glue <$> Csv.rowCommitter (Csv.CsvConfig f ',' Csv.NoHeader) (\(ls, v) -> ls <> [expt (Just 3) v]) <*|> qList (Map.toList m)+writeResult f m = writeFile f (show m) --- | Read results from file that are in CSV format.+-- | Read results from file readResult :: FilePath -> IO (Map.Map [Text] Double) readResult f = do-  r <- Csv.runCsv (Csv.CsvConfig f ',' Csv.NoHeader) Csv.fields-  let r' = [x | (Right x) <- r]-  let l = (\x -> (List.init x, fromRight 0 (A.parseOnly Csv.double (List.last x)))) <$> r'-  pure $ Map.fromList l+  a <- readFile f+  pure (read a)  -- | Comparison data between two results. data CompareResult = CompareResult {oldResult :: Maybe Double, newResult :: Maybe Double, noteResult :: Text} deriving (Show, Eq)@@ -222,7 +216,7 @@ parseGolden :: String -> Parser Golden parseGolden def =   Golden-    <$> option str (Options.Applicative.value ("other/" <> def <> ".csv") <> long "golden" <> short 'g' <> help "golden file name")+    <$> option str (Options.Applicative.value ("other/" <> def <> ".perf") <> long "golden" <> short 'g' <> help "golden file name")     <*> switch (long "check" <> short 'c' <> help "check versus a golden file")     <*> switch (long "record" <> short 'r' <> help "record the result to a golden file") 
src/Perf/Space.hs view
@@ -13,6 +13,7 @@     spaceLabels,     space,     allocation,+    Bytes(..),   ) where @@ -71,6 +72,7 @@       pure $ diffSpace s s' {-# INLINEABLE space #-} +-- | Number of bytes newtype Bytes = Bytes {unbytes :: Word64}   deriving (Show, Read, Eq, Ord, Num, Real, Enum, Integral) 
src/Perf/Time.hs view
@@ -12,8 +12,7 @@ -- -- For reference, a computer with a frequency of 2 GHz means that one cycle is equivalent to 0.5 nanoseconds. module Perf.Time-  (-    tick_,+  ( tick_,     warmup,     tick,     tickWHNF,@@ -160,7 +159,6 @@ {-# INLINEABLE ticksIO #-}  -- | tick as a 'StepMeasure'--- stepTime :: StepMeasure IO Cycles stepTime = StepMeasure start stop   where
src/Perf/Types.hs view
@@ -52,12 +52,10 @@ import Data.Text (Text) import Prelude - -- | Abstraction of a performance measurement within a monadic context. -- -- - measure applies a function to a value, returning a tuple of the performance measure, and the computation result. -- - measureM evaluates a monadic value and returns a performance-result tuple.--- data Measure m t = Measure   { measure :: forall a b. (a -> b) -> a -> m (t, b),     measureM :: forall a. m a -> m (t, a)@@ -86,7 +84,6 @@ {-# INLINEABLE repeated #-}  -- | Abstraction of a performance measurement with a pre and a post step wrapping the computation.--- data StepMeasure m t = forall i. StepMeasure {pre :: m i, post :: i -> m t}  instance (Functor m) => Functor (StepMeasure m) where@@ -138,7 +135,6 @@ {-# INLINEABLE multiM #-}  -- | Performance measurement transformer storing a 'Measure' and a map of named results.--- newtype PerfT m t a = PerfT   { measurePerf :: StateT (Measure m t, Map.Map Text t) m a   }