weigh: Measure allocations of a Haskell functions/values

[ bsd3, library, web ] [ Propose Tags ]

Please see README.md


[Skip to Readme]

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
weigh-maps

Weigh maps.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0, 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17 (info)
Change log CHANGELOG
Dependencies base (>=4.7 && <4.11), deepseq, mtl, process, split, template-haskell [details]
License BSD-3-Clause
Copyright FP Complete
Author Chris Done
Maintainer chrisdone@fpcomplete.com
Revised Revision 1 made by sjakobi at 2022-05-23T10:56:37Z
Category Web
Home page https://github.com/fpco/weigh#readme
Uploaded by ChrisDone at 2016-06-06T16:38:59Z
Distributions Arch:0.0.17, Debian:0.0.16, LTSHaskell:0.0.17, NixOS:0.0.17, Stackage:0.0.17
Reverse Dependencies 3 direct, 1 indirect [details]
Downloads 13271 total (86 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-06-06 [all 1 reports]

Readme for weigh-0.0.3

[back to package description]

weigh Build Status

Measures the memory usage of a Haskell value or function

Example use

import Weigh

-- | Weigh integers.
main :: IO ()
main =
  mainWith (do integers
               ints)

-- | Just counting integers.
integers :: Weigh ()
integers =
  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)

-- | We count ints and ensure that the allocations are optimized away
-- to only two 64-bit Ints (16 bytes).
ints :: Weigh ()
ints =
  do validateFunc "ints count 1" count 1 (maxAllocs 24)
     validateFunc "ints count 10" count 10 (maxAllocs 24)
     validateFunc "ints count 1000000" count 1000000 (maxAllocs 24)
  where count :: Int -> ()
        count 0 = ()
        count a = count (a - 1)

Output results:

Case                Bytes  GCs  Check
integers count 0        0    0  OK
integers count 1       32    0  OK
integers count 2       64    0  OK
integers count 3       96    0  OK
integers count 10     320    0  OK
integers count 100  3,200    0  OK
ints count 1            0    0  OK
ints count 10           0    0  OK
ints count 1000000      0    0  OK

You can try this out with stack test in the weight directory.

To try out other examples, try:

  • stack test :weigh-maps --flag weigh:weigh-maps