Skip to content

Instantly share code, notes, and snippets.

@nominolo
Created October 27, 2010 16:21
Show Gist options
  • Save nominolo/649370 to your computer and use it in GitHub Desktop.
Save nominolo/649370 to your computer and use it in GitHub Desktop.
murmur bench
{-# 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.
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment