packages feed

hashable-generics 1.1.5 → 1.1.6

raw patch · 3 files changed

+69/−6 lines, 3 filesdep +criteriondep ~QuickCheckdep ~basedep ~hashable

Dependencies added: criterion

Dependency ranges changed: QuickCheck, base, hashable, test-framework, test-framework-quickcheck2

Files

Data/Hashable/Generic.hs view
@@ -62,7 +62,7 @@ -- Note: The 'GHashable' type-class showing up in the type-signature is --       used internally and not exported on purpose. gHashWithSalt :: (Generic a, GHashable (Rep a)) => Int -> a -> Int-gHashWithSalt = gHashWithSalt_ salt $ from x+gHashWithSalt salt x = gHashWithSalt_ salt $ from x {-# INLINE gHashWithSalt #-}  -- | A value with bit pattern (01)* (or 5* in hexa), for any size of Int.
+ bench/Bench.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE DeriveGeneric #-}+{-# OPTIONS_GHC -Wall -O2 #-}+module Main ( main ) where++import Criterion+import Criterion.Main+import Data.Hashable+import Data.Hashable.Generic+import GHC.Generics++data HandRolled = HR0+                | HR1 (Maybe Int)+                | HR2 HandRolled HandRolled++data GenericRolled = GR0+                   | GR1 (Maybe Int)+                   | GR2 GenericRolled GenericRolled+    deriving Generic++instance Hashable HandRolled where+    hashWithSalt salt HR0       = hashWithSalt salt $ (Left () :: Either () ())+    hashWithSalt salt (HR1 mi)  = hashWithSalt salt $ (Right $ Left mi :: Either () (Either (Maybe Int) ()))+    hashWithSalt salt (HR2 x y) = hashWithSalt salt $ (Right $ Right (x, y) :: Either () (Either () (HandRolled, HandRolled)))++instance Hashable GenericRolled where+    hashWithSalt s x = gHashWithSalt s x++bigHandRolledDS :: HandRolled+bigHandRolledDS = let a = HR0+                      b = HR1 $ Just 1+                      c = HR1 $ Nothing+                      d = HR1 $ Just 3+                      e = HR2 a b+                      f = HR2 c d+                      g = HR2 e e+                      h = HR2 f f+                      i = HR2 e f+                      j = HR2 g h+                      k = HR2 i j+                   in HR2 k k++bigGenericRolledDS :: GenericRolled+bigGenericRolledDS = f bigHandRolledDS+    where+        f HR0       = GR0+        f (HR1 x)   = GR1 x+        f (HR2 x y) = GR2 (f x) (f y)++main :: IO ()+main = defaultMain [ bcompare [ bench "handrolled" $ whnf hash bigHandRolledDS+                              , bench "generic" $ whnf hash bigGenericRolledDS+                              ]+                   ]
hashable-generics.cabal view
@@ -1,5 +1,5 @@ name:                hashable-generics-version:             1.1.5+version:             1.1.6 synopsis:            Automatically generates Hashable instances with GHC.Generics. description:     This package provides a "GHC.Generics"-based 'Data.Hashable.Generic.gHashWithSalt'@@ -9,7 +9,7 @@     .     This package is heavily inspired by deepseq-generics, which you may also find     useful.-homepage:            https//github.com/wowus/hashable-generics+homepage:            https://github.com/wowus/hashable-generics license:             BSD3 license-file:        LICENSE author:              Clark Gaebel@@ -36,8 +36,18 @@     hs-source-dirs: test     build-depends:       base                        , hashable-                       , test-framework-                       , test-framework-quickcheck2-                       , QuickCheck+                       , test-framework ==0.6.*+                       , test-framework-quickcheck2 ==0.2.*+                       , QuickCheck ==2.5.*                        , hashable-generics                        , ghc-prim++benchmark compare-to-handrolled+    type: exitcode-stdio-1.0+    hs-source-dirs: bench+    main-is: Bench.hs+    build-depends: base+                 , hashable+                 , hashable-generics+                 , ghc-prim+                 , criterion ==0.6.*