Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE BangPatterns #-}
- import Criterion.Main
- import Data.Int
- import Data.Word
- import Data.List
- import Data.Digest.Murmur32
- main = defaultMain $
- [ bgroup "hash32 1..N" $
- [ bench "N=10000" $ whnf hash32upto 10000
- , bench "N=10000*" $ whnf hash32spec 10000]
- ]
- data FromTo = FromTo Word32 Word32
- instance Hashable32 FromTo where
- hash32Add (FromTo from to) h0 = go from to h0
- where go !from !to !h | from > to = h
- go !from !to !h =
- go (from + 1) to (hash32AddWord32 from h)
- hash32spec :: Word32 -> Hash32
- hash32spec n = hash32 (FromTo 1 n)
- hash32upto :: Word32 -> Hash32
- hash32upto n = hash32 [1..n]
- {-
- "N=10000*" gives me 3.7ns per word on my Core 2 Duo 2.4Ghz.
- -}
Add Comment
Please, Sign In to add comment