Copyright | (c) Michail Pardalos |
---|---|
License | 3-Clause BSD-style |
Maintainer | mpardalos@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Based on GHC.Datasize by Dennis Felsing
Synopsis
- recursiveSize :: a -> IO Int
- recursiveSizeNoGC :: a -> IO Int
- recursiveSizeNF :: NFData a => a -> IO Int
- closureSize :: a -> IO Int
Documentation
recursiveSize :: a -> IO Int Source #
Calculate the recursive size of GHC objects in Bytes. Note that the actual size in memory is calculated, so shared values are only counted once.
Call with
recursiveSize $! 2
to force evaluation to WHNF before calculating the size.
Call with
recursiveSize $!! "foobar"
($!! from Control.DeepSeq) to force full evaluation before calculating the
size.
A garbage collection is performed before the size is calculated, because the garbage collector would make heap walks difficult.
This function works very quickly on small data structures, but can be slow on large and complex ones. If speed is an issue it's probably possible to get the exact size of a small portion of the data structure and then estimate the total size from that.
recursiveSizeNoGC :: a -> IO Int Source #
Same as recursiveSize
except without performing garbage collection first.
Useful if you want to measure the size of many objects in sequence. You can
call performGC
once at first and then use this function to avoid multiple
unnecessary garbage collections.
recursiveSizeNF :: NFData a => a -> IO Int Source #
Calculate the recursive size of GHC objects in Bytes after calling
Control.DeepSeq.force on the data structure to force it into Normal Form.
Using this function requires that the data structure has an NFData
typeclass instance.
closureSize :: a -> IO Int Source #
Get the *non-recursive* size of an closure in words