Skip to content

Instantly share code, notes, and snippets.

@nh2
Last active October 19, 2020 17:26
Show Gist options
  • Save nh2/fa707e43791ab9abf4032bce8f2eb6ca to your computer and use it in GitHub Desktop.
Save nh2/fa707e43791ab9abf4032bce8f2eb6ca to your computer and use it in GitHub Desktop.

Revisions

  1. nh2 revised this gist Oct 19, 2020. No changes.
  2. nh2 revised this gist Oct 15, 2020. 1 changed file with 9 additions and 17 deletions.
    26 changes: 9 additions & 17 deletions SlopProblem.hs
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,27 @@
    -- Run with:
    -- ghc --make -O -threaded -fforce-recomp SlopProblem.hs && ./SlopProblem +RTS -N2 -s
    -- ghc --make -O -threaded -fforce-recomp SlopProblem.hs && command time ./SlopProblem +RTS -N1 -s
    --
    -- My output with ghc 8.6.5 on a 4-core machine:
    -- ...
    -- 336,707,456 bytes maximum residency (14 sample(s))
    -- 611,774,592 bytes maximum slop
    -- ...
    -- The slop reduces to 1 MB when `-N1` is used.
    -- ... 1716344maxresident)k
    -- The slop reduces to 1 MB when `-N1` is used, and the resident memory usage
    -- measured by `time` reduces from 1.7 GB to 0.6 GB.

    {-# LANGUAGE DeriveGeneric #-}

    import Control.DeepSeq
    import Control.Exception
    import qualified Data.Vector as V
    import Data.Word
    import GHC.Generics


    data WordTuple = WordTuple
    {-# UNPACK #-} !Word64
    {-# UNPACK #-} !Word64
    deriving (Eq, Ord, Show, Generic)

    instance NFData WordTuple
    data WordTuple = WordTuple {-# UNPACK #-} !Int {-# UNPACK #-} !Int


    main :: IO ()
    main = do
    putStrLn "Measuring 1M triples"
    _ <- evaluate $ force $ V.fromList
    putStrLn "Measuring 1M WordTuples"
    V.fromList
    [ WordTuple (fromIntegral (i+1)) (fromIntegral (i+2))
    | i <- [1..10000000::Int]
    ]
    return ()
    `seq`
    return ()
  3. nh2 created this gist Oct 15, 2020.
    35 changes: 35 additions & 0 deletions SlopProblem.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    -- Run with:
    -- ghc --make -O -threaded -fforce-recomp SlopProblem.hs && ./SlopProblem +RTS -N2 -s
    --
    -- My output with ghc 8.6.5 on a 4-core machine:
    -- ...
    -- 336,707,456 bytes maximum residency (14 sample(s))
    -- 611,774,592 bytes maximum slop
    -- ...
    -- The slop reduces to 1 MB when `-N1` is used.

    {-# LANGUAGE DeriveGeneric #-}

    import Control.DeepSeq
    import Control.Exception
    import qualified Data.Vector as V
    import Data.Word
    import GHC.Generics


    data WordTuple = WordTuple
    {-# UNPACK #-} !Word64
    {-# UNPACK #-} !Word64
    deriving (Eq, Ord, Show, Generic)

    instance NFData WordTuple


    main :: IO ()
    main = do
    putStrLn "Measuring 1M triples"
    _ <- evaluate $ force $ V.fromList
    [ WordTuple (fromIntegral (i+1)) (fromIntegral (i+2))
    | i <- [1..10000000::Int]
    ]
    return ()