Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List with length #103

Merged
merged 3 commits into from Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .travis.yml
Expand Up @@ -108,6 +108,15 @@ script:
else
echo "expected '$SRC_TGZ' not found";
exit 1;
fi;
cd ../

# Try to compile tests and benchmarks, run tests
# For some reason doesn't work with old cabal
- if [ ! $CABALVER = "1.16" ]; then
cabal install HUnit QuickCheck criterion random siphash test-framework test-framework-hunit test-framework-quickcheck2;
cabal configure -v2 --enable-tests --enable-benchmarks;
cabal test;
fi

# EOF
8 changes: 7 additions & 1 deletion Data/Hashable/Class.hs
Expand Up @@ -430,9 +430,15 @@ instance Hashable (StableName a) where
hash = hashStableName
hashWithSalt = defaultHashWithSalt

-- Auxillary type for Hashable [a] definition
data SPInt = SP !Int !Int

instance Hashable a => Hashable [a] where
{-# SPECIALIZE instance Hashable [Char] #-}
hashWithSalt = foldl' hashWithSalt
hashWithSalt salt arr = finalise (foldl' step (SP salt 0) arr)
where
finalise (SP s l) = hashWithSalt s l
step (SP s l) x = SP (hashWithSalt s x) (l + 1)

instance Hashable B.ByteString where
hashWithSalt salt bs = B.inlinePerformIO $
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/Benchmarks.hs
Expand Up @@ -98,13 +98,13 @@ main = do
withForeignPtr fp1Mb $ \ p1Mb ->
defaultMain
[ bgroup "hashPtr"
[ bench "5" $ hashPtr p5 5
, bench "8" $ hashPtr p8 8
, bench "11" $ hashPtr p11 11
, bench "40" $ hashPtr p40 40
, bench "128" $ hashPtr p128 128
, bench "512" $ hashPtr p512 512
, bench "2^20" $ hashPtr p1Mb mb
[ bench "5" $ whnfIO $ hashPtr p5 5
, bench "8" $ whnfIO $ hashPtr p8 8
, bench "11" $ whnfIO $ hashPtr p11 11
, bench "40" $ whnfIO $ hashPtr p40 40
, bench "128" $ whnfIO $ hashPtr p128 128
, bench "512" $ whnfIO $ hashPtr p512 512
, bench "2^20" $ whnfIO $ hashPtr p1Mb mb
]
, bgroup "hashByteArray"
[ bench "5" $ whnf (hashByteArray ba5 0) 5
Expand Down
2 changes: 1 addition & 1 deletion hashable.cabal
Expand Up @@ -104,7 +104,7 @@ benchmark benchmarks
build-depends:
base,
bytestring,
criterion,
criterion >= 1.0,
ghc-prim,
siphash,
text
Expand Down