packages feed

data-size 0.1.1.6 → 0.1.1.7

raw patch · 3 files changed

+85/−57 lines, 3 filesdep +deepseq

Dependencies added: deepseq

Files

Data/Size/Base.hs view
@@ -37,6 +37,7 @@     , (<>)     ) where+import           Control.DeepSeq  import qualified Data.List        as L import qualified Data.Map.Strict  as M@@ -125,8 +126,8 @@  data Size     = Size-      { _objCnt  :: ! Int-      , _byteCnt :: ! Int+      { _objCnt  :: {-# UNPACK #-} ! Int+      , _byteCnt :: {-# UNPACK #-} ! Int       }     deriving (Eq, Show) @@ -175,33 +176,37 @@       deriving (Show)  instance Monoid SizeTable where-    mempty = ST M.empty+    mempty = ST $! M.empty     mappend (ST t1) (ST t2)-        = ST $ M.unionWith (<>) t1 t2+        = ST $! M.unionWith (<>) t1 t2     mconcat         = L.foldl' mappend mempty  instance Scale SizeTable where     i .*. (ST t)         | i == 0    = mempty-        | otherwise = ST $ M.map (i .*.) t+        | otherwise = ST $! M.map (i .*.) t  -- --------------------  data SizeStatistics     = SST-      { _nameof :: String-      , _accu   :: Size-      , _parts  :: SizeTable+      { _nameof :: ! String+      , _accu   :: ! Size+      , _parts  :: ! SizeTable       } --    deriving Show +mkSST :: String -> Size -> SizeTable -> SizeStatistics+mkSST n c t+    = rnf n `seq` SST n c t+ instance Show SizeStatistics where show = showStats  instance Monoid SizeStatistics where-    mempty = SST "" mempty mempty+    mempty = mkSST "" mempty mempty     mappend (SST n1 c1 t1) (SST n2 c2 t2)-        = SST n c t+        = mkSST n c t           where             n = if null n1 then n2 else n1             c = c1 <> c2@@ -211,7 +216,7 @@  instance Scale  SizeStatistics where     i .*. (SST n c t)-        = SST n (i .*. c) (i .*. t)+        = mkSST n (i .*. c) (i .*. t)  -- -------------------- @@ -234,8 +239,10 @@   typeName :: Typeable a => a -> String-typeName-    = show . typeOf+typeName x+    = (tyConModule . fst . splitTyConApp $ t) ++ "." ++ show t+      where+        t = typeOf x  -- ------------------------------------------------------------ 
Data/Size/Instances.hs view
@@ -4,19 +4,19 @@ module Data.Size.Instances where -import qualified Data.List            as L+import qualified Data.List                     as L import           Data.Size.Base -import qualified Data.ByteString         as BS-import qualified Data.ByteString.Lazy    as BL+import qualified Data.ByteString.Internal      as BS+import qualified Data.ByteString.Lazy.Internal as BL import           Data.Int-import qualified Data.IntMap             as IM-import qualified Data.IntSet             as IS-import qualified Data.Map                as M-import qualified Data.Text.Internal      as T (Text(..)) -import qualified Data.Text.Lazy.Internal as TL+import qualified Data.IntMap                   as IM+import qualified Data.IntSet                   as IS+import qualified Data.Map.Strict               as M+import qualified Data.Text.Internal            as T (Text (..))+import qualified Data.Text.Lazy.Internal       as TL import           Data.Word-import qualified Foreign.Storable        as FS+import qualified Foreign.Storable              as FS  -- import qualified Data.ByteString.Short as SS -- requires bytestring-0.10.4 @@ -62,6 +62,14 @@ dataOfDouble     = dataOfStorable (undefined :: Double) +dataOfWord8 :: Bytes+dataOfWord8+    = dataOf (undefined ::Word8)++dataOfWord16 :: Bytes+dataOfWord16+    = dataOf (undefined::Word16)+ -- --------------------  instance (Sizeable t1, Sizeable t2) => Sizeable (t1, t2) where@@ -250,17 +258,25 @@ -}  instance Sizeable BS.ByteString where-    dataOf bs+    dataOf (BS.PS _payload _offset len)         = (8 .*. dataOfPtr)                             -- 8 words for length field and pointers           <> (wordAlign $                               -- size of byte sequence-              BS.length bs .*. dataOf (undefined ::Word8)+              len .*. dataOfWord8              )---  bytesOf---      = dataOfObj . dataOf                            -- default impl. -    statsOf s-        = mkStats s+    statsOf x@(BS.PS _payload offset len)+        = st3+          where+            tn  = nameOf x+            st1 = mkStats x                             -- extra statistics for real payload+                                                        -- and overhead by unused prefixes+            st2 =     addPart tn "<chars>"   (mkSize $    len .*. dataOfWord8) st1+            st3 | offset == 0+                    = st2+                | otherwise+                    = addPart tn "<offsets>" (mkSize $ offset .*. dataOfWord8) st2 + {- requires bytestring-0.10.4  instance Sizeable SS.ShortByteString where@@ -285,53 +301,57 @@ -}  instance Sizeable BL.ByteString where-    nameOf-        = (++ " (lazy)") . typeName--    dataOf bs-        = length cs .*. (dataOfObj $ dataOfPtr <> dataOfPtr)-          <>-          (mconcat . L.map bytesOf $ cs)-        where-          cs = BL.toChunks bs+    dataOf (BL.Empty)+        = dataOfSingleton -    bytesOf             -- ByteString is handled as a single object,-        = dataOf        -- all space is already accumulated in dataOf+    dataOf (BL.Chunk _c _r)+        = 1 .*. dataOfPtr+          -- c is not counted here, because it's counted in statsOf c+          -- but it's an unpacked field (a bit tricky) -    statsOf-        = mkStats+    statsOf x+       = case x of+            (BL.Empty    ) -> constrStats "Empty" x+            (BL.Chunk c r) -> constrStats "Chunk" x <> statsOf c <> statsOf r  -- ------------------------------------------------------------  -- the overhead of 8 words + constructor word is copied from -- ByteString. Precise figures not yet found, except the issue, -- that Text is the same as a ByteString with Word16 instead of Word8--- for the real data +-- for the real data  instance Sizeable T.Text where     dataOf (T.Text _payload _offset len)         = (8 .*. dataOfPtr)                             -- 8 words for length field and pointers           <> (wordAlign $                               -- size of Word16 sequence-              len .*. dataOf (undefined::Word16)+              len .*. dataOfWord16              ) -    statsOf-        = mkStats+    statsOf x@(T.Text _payload offset len)+        = st3+          where+            tn  = nameOf x+            st1 = mkStats x                             -- extra statistics for real payload+                                                        -- and overhead by unused prefixes+            st2 =     addPart tn "<chars>"   (mkSize $    len .*. dataOfWord16) st1+            st3 | offset == 0+                    = st2+                | otherwise+                    = addPart tn "<offsets>" (mkSize $ offset .*. dataOfWord16) st2  instance Sizeable TL.Text where-    nameOf-        = (++ " (lazy)") . typeName-     dataOf (TL.Empty )         = dataOfSingleton-    dataOf (TL.Chunk c r)-        = dataOfObj $ dataOf c <> dataOf r-                        -- dataOf c, not bytesOf c, because c is an unpacked strict field -    bytesOf             -- lazy Text is counted as a single object-        = dataOf        -- all space is already accumulated in dataOf- -    statsOf-        = mkStats+    dataOf (TL.Chunk _c _r)+        = 1 .*. dataOfPtr+          -- c is not counted here, because it's counted in statsOf c+          -- but it's an unpacked field (a bit tricky)++    statsOf x+        = case x of+            (TL.Empty    ) -> constrStats "Empty" x+            (TL.Chunk c r) -> constrStats "Chunk" x <> statsOf c <> statsOf r  -- ------------------------------------------------------------
data-size.cabal view
@@ -1,5 +1,5 @@ name:                data-size-version:             0.1.1.6+version:             0.1.1.7 synopsis:            Profiling of data structures description:         Profiling of data structures                      for counting the # of object allocated for a value@@ -27,6 +27,7 @@   build-depends:       base        >= 4.6 && < 5                      , bytestring  >= 0.10                      , containers  >= 0.5+                     , deepseq     >= 1.2                      , text        >= 0.11.1    hs-source-dirs:      .