HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Moduleweigh-0.0.18Haskell2010

Weigh

Framework for seeing how much a function allocates.

WARNING: weigh is incompatible with profiling. It reports much more allocations with profiling turned on.

Example:

import Weigh
main =
  mainWith (do func "integers count 0" count 0
               func "integers count 1" count 1
               func "integers count 2" count 2
               func "integers count 3" count 3
               func "integers count 10" count 10
               func "integers count 100" count 100)
  where count :: Integer -> ()
        count 0 = ()
        count a = count (a - 1)

Use wgroup to group sets of tests.

Contents
  1. Main entry points
  2. Configuration
  3. Simple combinators
  4. Validating combinators
  5. Validators
  6. Types
  7. Handy utilities
  8. Internals
Synopsis
  • Packageweigh-0.0.18
  • Exports28
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceWeigh.hs

Main entry points

Configuration

datadata Column

Table column.

Constructors

  • Case

    Case name for the column

  • Allocated

    Total bytes allocated

  • GCs

    Total number of GCs

  • Live

    Total amount of live data in the heap

  • Check

    Table column indicating about the test status

  • Max

    Maximum residency memory in use

  • MaxOS

    Maximum memory in use by the RTS. Valid only for GHC >= 8.2.2. For unsupported GHC, this is reported as 0.

  • WallTime

    Rough execution time. For general indication, not a benchmark tool.

Instances3Enum, Eq, Show

Simple combinators

valuefunc
  1. :: NFData a
  2. => String

    Name of the case.

  3. -> (b -> a)

    Function that does some action to measure.

  4. -> b

    Argument to that function.

  5. -> Weigh ()

Weigh a function applied to an argument.

Implemented in terms of validateFunc.

valuefunc' :: (NFData a, NFData b) => String -> (b -> a) -> b -> Weigh ()

Weigh a function applied to an argument. Unlike func, the argument is evaluated to normal form before the function is applied.

valueio
  1. :: NFData a
  2. => String

    Name of the case.

  3. -> (b -> IO a)

    Action that does some IO to measure.

  4. -> b

    Argument to that function.

  5. -> Weigh ()

Weigh an action applied to an argument.

Implemented in terms of validateAction.

Validating combinators

valuevalidateAction
  1. :: NFData a
  2. => String

    Name of the action.

  3. -> (b -> IO a)

    The function which performs some IO.

  4. -> b

    Argument to the function. Doesn't have to be forced.

  5. -> (Weight -> Maybe String)

    A validating function, returns maybe an error.

  6. -> Weigh ()

Weigh an IO action, validating the result.

valuevalidateFunc
  1. :: NFData a
  2. => String

    Name of the function.

  3. -> (b -> a)

    The function which calculates something.

  4. -> b

    Argument to the function. Doesn't have to be forced.

  5. -> (Weight -> Maybe String)

    A validating function, returns maybe an error.

  6. -> Weigh ()

Weigh a function, validating the result

Validators

Types

Handy utilities

Internals

valueweighFunc
  1. :: NFData a
  2. => (b -> a)

    A function whose memory use we want to measure.

  3. -> b

    Argument to the function. Doesn't have to be forced.

  4. -> IO (Word64, Word32, Word64, Word64, Word64)

    Bytes allocated and garbage collections.

Weigh a pure function. This function is built on top of weighFuncResult, which is heavily documented inside

valueweighFuncResult
  1. :: NFData a
  2. => (b -> a)

    A function whose memory use we want to measure.

  3. -> b

    Argument to the function. Doesn't have to be forced.

  4. -> IO (a, (Word64, Word32, Word64, Word64, Word64))

    Result, Bytes allocated, GCs.

Weigh a pure function and return the result. This function is heavily documented inside.

valueweighActionResult
  1. :: NFData a
  2. => (b -> IO a)

    A function whose memory use we want to measure.

  3. -> b

    Argument to the function. Doesn't have to be forced.

  4. -> IO (a, (Word64, Word32, Word64, Word64, Word64))

    Result, Bytes allocated and GCs.

Weigh an IO action, and return the result. This function is heavily documented inside.

datadata Grouped a

Some grouped thing.

Constructors

Instances8Functor, Foldable, Traversable, Eq, Show, Generic, …