HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

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.

  • 6 types
  • 22 values
  • Packageweigh-0.0.18
  • Exports28
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceWeigh.hs

Main entry points

2 declarations

Configuration

7 declarations
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

6 declarations
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

2 declarations
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

1 declaration

Types

2 declarations
newtypenewtype Weigh a
#

Weigh specification monad.

Instances3Monad, Functor, Applicative

Handy utilities

2 declarations

Internals

6 declarations
valueweighDispatch
  1. :: Maybe String

    The content of then env variable WEIGH_CASE.

  2. -> [Grouped Action]

    Weigh name:action mapping.

  3. -> IO (Maybe [Grouped Weight])
#

Weigh a set of actions. The value of the actions are forced completely to ensure they are fully allocated.

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, …