packages feed

binary-typed 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+111/−11 lines, 2 filesdep ~basedep ~binarydep ~bytestring

Dependency ranges changed: base, binary, bytestring

Files

+ benchmark/MessageLength.hs view
@@ -0,0 +1,84 @@+module Main where++import Data.Binary+import Data.Binary.Typed++import qualified Data.ByteString.Lazy as BSL+import Data.Typeable (Typeable)+import Data.Int+import Text.Printf++main :: IO ()+main = do+      putStrLn "Comparison of message lengths depending on serialization method"+      putStrLn "==============================================================="+      putStrLn ""+      putStrLn (ppr (measure "maxBound :: Int"  (maxBound :: Int)))+      putStrLn (ppr (measure "\"Hello\""        "Hello"))+      putStrLn (ppr (measure "100 chars lipsum" lipsum))+      putStrLn (ppr (measure "Right (Left \"Hello\") :: Either (Char, Int) (Either String (Maybe Integer))"+                             (Right (Left "Hello") :: Either (Char, Int) (Either String (Maybe Integer)))))+++lipsum :: String+lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam\+         \ vitae lacinia tellus. Maecenas posuere."++data EncodeLengths = EL { info         :: String+                        , binary       :: Int64+                        , typedUntyped :: Int64+                        , typedHashed  :: Int64+                        , typedShown   :: Int64+                        , typedFull    :: Int64+                        }++-- | Prettyprint 'EncodeLengths'+ppr :: EncodeLengths -> String+ppr el = unlines [ info el+                 , printf "  Binary:        %d" (binary el)+                 , printf "  Typed/Untyped: %d (+%d, +%2.2f%%)"+                          (typedUntyped el)+                          (absolute (binary el) (typedUntyped el))+                          (percent  (binary el) (typedUntyped el))+                 , printf "  Typed/Hashed:  %d (+%d, +%2.2f%%)"+                          (typedHashed el)+                          (absolute (binary el) (typedHashed el))+                          (percent  (binary el) (typedHashed el))+                 , printf "  Typed/Shown:   %d (+%d, +%2.2f%%)"+                          (typedShown el)+                          (absolute (binary el) (typedShown el))+                          (percent  (binary el) (typedShown el))+                 , printf "  Typed/Full:    %d (+%d, +%2.2f%%)"+                          (typedFull el)+                          (absolute (binary el) (typedFull el))+                          (percent  (binary el) (typedFull el))+                 ]++-- | Calculate how much percent the first parameter deviates from the second.+percent :: Int64 -> Int64 -> Double+percent base x = let x'    = fromIntegral x+                     base' = fromIntegral base+                 in  abs ((x'-base')*100/base')+++-- | Absolute deviation of the second from the first parameter+absolute :: Int64 -> Int64 -> Int64+absolute base x = x - base++-- | Measure the message lengths generated by different encodings.+measure :: (Binary a, Typeable a) => String -> a -> EncodeLengths+measure i x = EL { info = i+                 , binary       = BSL.length binary'+                 , typedUntyped = BSL.length typedUntyped'+                 , typedHashed  = BSL.length typedHashed'+                 , typedShown   = BSL.length typedShown'+                 , typedFull    = BSL.length typedFull'+                 }++      where++      binary'       = encode              x+      typedUntyped' = encodeTyped Untyped x+      typedHashed'  = encodeTyped Hashed  x+      typedShown'   = encodeTyped Shown   x+      typedFull'    = encodeTyped Full    x
binary-typed.cabal view
@@ -1,5 +1,5 @@ name:          binary-typed-version:       0.1.0.0+version:       0.1.0.1 synopsis:      Type-safe binary serialization Description:       `Binary` serialization tagged with type information, allowing for@@ -31,16 +31,17 @@       <<http://i.imgur.com/nY6hgMP.png>>       .       <doc/bench-overview.png (local copy)>-homepage:      https://github.com/quchen/binary-typed-bug-reports:   https://github.com/quchen/binary-typed/issues-license:       BSD2-license-file:  LICENSE-author:        David Luposchainsky-maintainer:    dluposchainsky on googles email service-copyright:     David Luposchainsky-category:      Data, Serialization-build-type:    Simple-cabal-version: >= 1.20+homepage:           https://github.com/quchen/binary-typed+bug-reports:        https://github.com/quchen/binary-typed/issues+license:            BSD2+license-file:       LICENSE+author:             David Luposchainsky+maintainer:         dluposchainsky on googles email service+copyright:          David Luposchainsky+category:           Data, Serialization+build-type:         Simple+cabal-version:      >= 1.10+tested-with:        GHC == 7.8.2 extra-source-files: doc/*.png  source-repository head@@ -75,6 +76,21 @@                          , tasty            >= 0.8                          , tasty-hunit      >= 0.8                          , tasty-quickcheck >= 0.8++++test-suite message-length+      default-language:    Haskell2010+      type:                exitcode-stdio-1.0+      hs-source-dirs:      benchmark+      main-is:             MessageLength.hs+      build-depends:       base+                         , binary+                         , binary-typed+                         , bytestring+      ghc-options:         -Wall++  benchmark criterion       default-language:    Haskell2010