Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use Hashable's hash method directly, starting with ByteString

  • Loading branch information...
commit 240626fae4f1f9219dcc0814bef10d09e0f99617 1 parent b0715b7
@bos authored
Showing with 19 additions and 3 deletions.
  1. +18 −2 benchmarks/Benchmarks.hs
  2. +1 −1  benchmarks/Makefile
View
20 benchmarks/Benchmarks.hs
@@ -8,6 +8,7 @@ import Data.Hashable
import Foreign.ForeignPtr
import GHC.Exts
import GHC.ST (ST(..))
+import qualified Data.ByteString as B
-- Benchmark English words (5 and 8), base64 encoded integers (11),
-- SHA1 hashes as hex (40), and large blobs (1 Mb).
@@ -20,14 +21,20 @@ main = do
fp40 <- mallocForeignPtrBytes 40
let !mb = 2^(20 :: Int) -- 1 Mb
fp1Mb <- mallocForeignPtrBytes mb
-
+
-- We don't care about the contents of these either.
let !ba5 = new 5
!ba8 = new 8
!ba11 = new 11
!ba40 = new 40
!ba1Mb = new mb
-
+
+ let !bs5 = B.pack [0..4]
+ !bs8 = B.pack [0..7]
+ !bs11 = B.pack [0..10]
+ !bs40 = B.pack [0..39]
+ !bs1Mb = B.pack . map fromIntegral $ [0..999999::Int]
+
withForeignPtr fp5 $ \ p5 ->
withForeignPtr fp8 $ \ p8 ->
withForeignPtr fp11 $ \ p11 ->
@@ -48,6 +55,15 @@ main = do
, bench "40" $ whnf (hashByteArray ba40 0) 40
, bench "2^20" $ whnf (hashByteArray ba1Mb 0) mb
]
+ , bgroup "hash"
+ [ bgroup "ByteString"
+ [ bench "5" $ whnf hash bs5
+ , bench "8" $ whnf hash bs8
+ , bench "11" $ whnf hash bs11
+ , bench "40" $ whnf hash bs40
+ , bench "2^20" $ whnf hash bs1Mb
+ ]
+ ]
]
data ByteArray = BA { unBA :: !ByteArray# }
View
2  benchmarks/Makefile
@@ -4,7 +4,7 @@ lib := ../dist/build/libHS$(package)-$(version).a
ghc := ghc
ghc-flags := -Wall -O -hide-all-packages \
-package-conf ../dist/package.conf.inplace -package base \
- -package hashable -package criterion \
+ -package hashable -package criterion -package bytestring \
-package deepseq -package ghc-prim
%.o: %.hs
Please sign in to comment.
Something went wrong with that request. Please try again.