Main.hs (1716B)
1 {-# OPTIONS_GHC -fno-warn-orphans #-} 2 {-# LANGUAGE DeriveGeneric #-} 3 {-# LANGUAGE OverloadedStrings #-} 4 {-# LANGUAGE StandaloneDeriving #-} 5 6 module Main where 7 8 import Criterion.Main 9 import qualified Data.ByteString as BS 10 import qualified Data.ByteString.Base32 as Base32 11 import qualified Data.ByteString.Bech32 as Bech32 12 import GHC.Generics 13 import qualified Reference.Bech32 as R 14 import Control.DeepSeq 15 16 deriving instance Generic R.Word5 17 instance NFData R.Word5 18 19 main :: IO () 20 main = defaultMain [ 21 suite 22 ] 23 24 base32_encode :: Benchmark 25 base32_encode = bgroup "base32 encode" [ 26 bench "120b" $ nf Base32.encode "jtobin was here" 27 , bench "128b (non 40-bit multiple length)" $ 28 nf Base32.encode "jtobin was here!" 29 , bench "240b" $ nf Base32.encode "jtobin was herejtobin was here" 30 ] 31 32 base32_decode :: Benchmark 33 base32_decode = bgroup "base32 decode" [ 34 bench "120b" $ nf Base32.decode "df6x7cnfdcs8wctnyp5x2un9" 35 , bench "128b (non 40-bit multiple length)" $ 36 nf Base32.decode "df6x7cnfdcs8wctnyp5x2un9yy" 37 ] 38 39 bech32_encode :: Benchmark 40 bech32_encode = bgroup "bech32 encode" [ 41 bench "120b" $ nf (Bech32.encode "bc") "jtobin was here" 42 ] 43 44 bech32_decode :: Benchmark 45 bech32_decode = bgroup "bech32 decode" [ 46 bench "120b" $ nf Bech32.decode "bc1df6x7cnfdcs8wctnyp5x2un9f0pw8y" 47 ] 48 49 suite :: Benchmark 50 suite = bgroup "benchmarks" [ 51 bgroup "ppad-bech32" [ 52 base32_encode 53 , base32_decode 54 , bech32_encode 55 , bech32_decode 56 ] 57 , bgroup "reference" [ 58 bgroup "bech32 encode" [ 59 bench "120b" $ nf (refEncode "bc") "jtobin was here" 60 ] 61 ] 62 ] 63 where 64 refEncode h a = R.bech32Encode h (R.toBase32 (BS.unpack a)) 65