base16

Pure Haskell base16 encoding/decoding (docs.ppad.tech/base16).
git clone git://git.ppad.tech/base16.git
Log | Files | Refs | README | LICENSE

Main.hs (2271B)


      1 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
      2 {-# LANGUAGE OverloadedStrings #-}
      3 {-# LANGUAGE PackageImports #-}
      4 
      5 module Main where
      6 
      7 import Criterion.Main
      8 import qualified Data.ByteString as BS
      9 import qualified "ppad-base16" Data.ByteString.Base16 as B16
     10 import qualified "base16-bytestring" Data.ByteString.Base16 as R0
     11 import qualified "base16" Data.ByteString.Base16 as R1
     12 
     13 main :: IO ()
     14 main = defaultMain [
     15     minimal_encode
     16   , minimal_decode
     17   ]
     18 
     19 minimal_encode :: Benchmark
     20 minimal_encode = bench "ppad-base16" $ nf B16.encode (BS.replicate 1024 0x00)
     21 
     22 minimal_decode :: Benchmark
     23 minimal_decode = bench "ppad-base16" $ nf B16.decode
     24   (B16.encode (BS.replicate 512 0x00))
     25 
     26 encode :: Benchmark
     27 encode = bgroup "encode" [
     28     bench "ppad-base16" $ nf B16.encode (BS.replicate 1024 0x00)
     29   , bench "base16-bytestring" $ nf R0.encode (BS.replicate 1024 0x00)
     30   , bench "base16" $ nf R1.encodeBase16' (BS.replicate 1024 0x00)
     31   ]
     32 
     33 decode :: Benchmark
     34 decode = bgroup "decode" [
     35     bench "ppad-base16" $ nf B16.decode
     36       (B16.encode (BS.replicate 512 0x00))
     37   , bench "base16-bytestring" $ nf R0.decode
     38       (B16.encode (BS.replicate 512 0x00))
     39   , bench "base16" $ nf R1.decodeBase16Untyped
     40       (B16.encode (BS.replicate 512 0x00))
     41   ]
     42 
     43 decode_various :: Benchmark
     44 decode_various = bgroup "base16" [
     45     bench "1024B input" $ nf B16.decode (B16.encode (BS.replicate 512 0x00))
     46   , bench "1026B input" $ nf B16.decode (B16.encode (BS.replicate 513 0x00))
     47   , bench "1028B input" $ nf B16.decode (B16.encode (BS.replicate 514 0x00))
     48   , bench "1030B input" $ nf B16.decode (B16.encode (BS.replicate 515 0x00))
     49   , bench "1032B input" $ nf B16.decode (B16.encode (BS.replicate 516 0x00))
     50   , bench "1034B input" $ nf B16.decode (B16.encode (BS.replicate 517 0x00))
     51   , bench "1036B input" $ nf B16.decode (B16.encode (BS.replicate 518 0x00))
     52   , bench "1038B input" $ nf B16.decode (B16.encode (BS.replicate 519 0x00))
     53   , bench "1040B input" $ nf B16.decode (B16.encode (BS.replicate 520 0x00))
     54   ]
     55 
     56 encode_various :: Benchmark
     57 encode_various = bgroup "base16" [
     58     bench "1024B input" $ nf B16.encode (BS.replicate 1024 0x00)
     59   , bench "1023B input" $ nf B16.encode (BS.replicate 1023 0x00)
     60   , bench "1022B input" $ nf B16.encode (BS.replicate 1022 0x00)
     61   ]