Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Hashable's hash method directly, starting with ByteString

  • Loading branch information...
commit 240626fae4f1f9219dcc0814bef10d09e0f99617 1 parent b0715b7
Bryan O'Sullivan authored

Showing 2 changed files with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. +18 2 benchmarks/Benchmarks.hs
  2. +1 1  benchmarks/Makefile
20 benchmarks/Benchmarks.hs
@@ -8,6 +8,7 @@ import Data.Hashable
8 8 import Foreign.ForeignPtr
9 9 import GHC.Exts
10 10 import GHC.ST (ST(..))
  11 +import qualified Data.ByteString as B
11 12
12 13 -- Benchmark English words (5 and 8), base64 encoded integers (11),
13 14 -- SHA1 hashes as hex (40), and large blobs (1 Mb).
@@ -20,14 +21,20 @@ main = do
20 21 fp40 <- mallocForeignPtrBytes 40
21 22 let !mb = 2^(20 :: Int) -- 1 Mb
22 23 fp1Mb <- mallocForeignPtrBytes mb
23   -
  24 +
24 25 -- We don't care about the contents of these either.
25 26 let !ba5 = new 5
26 27 !ba8 = new 8
27 28 !ba11 = new 11
28 29 !ba40 = new 40
29 30 !ba1Mb = new mb
30   -
  31 +
  32 + let !bs5 = B.pack [0..4]
  33 + !bs8 = B.pack [0..7]
  34 + !bs11 = B.pack [0..10]
  35 + !bs40 = B.pack [0..39]
  36 + !bs1Mb = B.pack . map fromIntegral $ [0..999999::Int]
  37 +
31 38 withForeignPtr fp5 $ \ p5 ->
32 39 withForeignPtr fp8 $ \ p8 ->
33 40 withForeignPtr fp11 $ \ p11 ->
@@ -48,6 +55,15 @@ main = do
48 55 , bench "40" $ whnf (hashByteArray ba40 0) 40
49 56 , bench "2^20" $ whnf (hashByteArray ba1Mb 0) mb
50 57 ]
  58 + , bgroup "hash"
  59 + [ bgroup "ByteString"
  60 + [ bench "5" $ whnf hash bs5
  61 + , bench "8" $ whnf hash bs8
  62 + , bench "11" $ whnf hash bs11
  63 + , bench "40" $ whnf hash bs40
  64 + , bench "2^20" $ whnf hash bs1Mb
  65 + ]
  66 + ]
51 67 ]
52 68
53 69 data ByteArray = BA { unBA :: !ByteArray# }
2  benchmarks/Makefile
@@ -4,7 +4,7 @@ lib := ../dist/build/libHS$(package)-$(version).a
4 4 ghc := ghc
5 5 ghc-flags := -Wall -O -hide-all-packages \
6 6 -package-conf ../dist/package.conf.inplace -package base \
7   - -package hashable -package criterion \
  7 + -package hashable -package criterion -package bytestring \
8 8 -package deepseq -package ghc-prim
9 9
10 10 %.o: %.hs

0 comments on commit 240626f

Please sign in to comment.
Something went wrong with that request. Please try again.