Guest User

Untitled

a guest
Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. {-# LANGUAGE BangPatterns #-}
  2. import Criterion.Main
  3.  
  4. import Data.Int
  5. import Data.Word
  6. import Data.List
  7.  
  8. import Data.Digest.Murmur32
  9.  
  10. main = defaultMain $
  11. [ bgroup "hash32 1..N" $
  12. [ bench "N=10000" $ whnf hash32upto 10000
  13. , bench "N=10000*" $ whnf hash32spec 10000]
  14. ]
  15.  
  16. data FromTo = FromTo Word32 Word32
  17.  
  18. instance Hashable32 FromTo where
  19. hash32Add (FromTo from to) h0 = go from to h0
  20. where go !from !to !h | from > to = h
  21. go !from !to !h =
  22. go (from + 1) to (hash32AddWord32 from h)
  23.  
  24. hash32spec :: Word32 -> Hash32
  25. hash32spec n = hash32 (FromTo 1 n)
  26.  
  27. hash32upto :: Word32 -> Hash32
  28. hash32upto n = hash32 [1..n]
  29.  
  30. {-
  31. "N=10000*" gives me 3.7ns per word on my Core 2 Duo 2.4Ghz.
  32. -}
Add Comment
Please, Sign In to add comment