commit 2d3555d06eda78b3aa8abc195df5d62885c0b782
parent 1b4becd1721367aa48ec992d0c74cc2fec17cbda
Author: Jared Tobin <jared@jtobin.io>
Date: Fri, 17 Jan 2025 17:17:45 +0400
lib: basic bench & extremely basic test skeletons
Diffstat:
4 files changed, 96 insertions(+), 56 deletions(-)
diff --git a/bench/Main.hs b/bench/Main.hs
@@ -1,74 +1,54 @@
+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
+{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports #-}
module Main where
import Criterion.Main
+import qualified Data.ByteString as BS
import qualified "ppad-base16" Data.ByteString.Base16 as B16
import qualified "base16-bytestring" Data.ByteString.Base16 as R0
import qualified "base16" Data.ByteString.Base16 as R1
main :: IO ()
-main = defaultMain [ suite ]
-
-base16_encode :: Benchmark
-base16_encode = bgroup "base16 encode" [
- bench "120b" $ nf B16.encode "jtobin was here"
- , bench "240b" $ nf B16.encode "jtobin was herebenching stuff."
- ]
-
-base16_encode' :: Benchmark
-base16_encode' = bgroup "base16 encode" [
- bench "120b" $ nf B16.encode' "jtobin was here"
- , bench "240b" $ nf B16.encode' "jtobin was herebenching stuff."
+main = defaultMain [
+ encode
+ , decode
]
-base16_decode :: Benchmark
-base16_decode = bgroup "base16 decode" [
- bench "120b" $ nf B16.decode "6a746f62696e207761732068657265"
- , bench "240b" $ nf B16.decode
- "6a746f62696e20776173206865726562656e6368696e672073747566662e"
+encode :: Benchmark
+encode = bgroup "encode" [
+ bench "ppad-base16" $ nf B16.encode (BS.replicate 1024 0x00)
+ , bench "base16-bytestring" $ nf R0.encode (BS.replicate 1024 0x00)
+ , bench "base16" $ nf R1.encodeBase16' (BS.replicate 1024 0x00)
]
-r0_encode :: Benchmark
-r0_encode = bgroup "base16 encode" [
- bench "120b" $ nf R0.encode "jtobin was here"
- , bench "240b" $ nf R0.encode "jtobin was herebenching stuff."
+decode :: Benchmark
+decode = bgroup "decode" [
+ bench "ppad-base16" $ nf B16.decode
+ (B16.encode (BS.replicate 512 0x00))
+ , bench "base16-bytestring" $ nf R0.decode
+ (B16.encode (BS.replicate 512 0x00))
+ , bench "base16" $ nf R1.decodeBase16Untyped
+ (B16.encode (BS.replicate 512 0x00))
]
-r0_decode :: Benchmark
-r0_decode = bgroup "base16 decode" [
- bench "120b" $ nf R0.decode "6a746f62696e207761732068657265"
- , bench "240b" $ nf R0.decode
- "6a746f62696e20776173206865726562656e6368696e672073747566662e"
+decode_various :: Benchmark
+decode_various = bgroup "base16" [
+ bench "1024B input" $ nf B16.decode (B16.encode (BS.replicate 512 0x00))
+ , bench "1026B input" $ nf B16.decode (B16.encode (BS.replicate 513 0x00))
+ , bench "1028B input" $ nf B16.decode (B16.encode (BS.replicate 514 0x00))
+ , bench "1030B input" $ nf B16.decode (B16.encode (BS.replicate 515 0x00))
+ , bench "1032B input" $ nf B16.decode (B16.encode (BS.replicate 516 0x00))
+ , bench "1034B input" $ nf B16.decode (B16.encode (BS.replicate 517 0x00))
+ , bench "1036B input" $ nf B16.decode (B16.encode (BS.replicate 518 0x00))
+ , bench "1038B input" $ nf B16.decode (B16.encode (BS.replicate 519 0x00))
+ , bench "1040B input" $ nf B16.decode (B16.encode (BS.replicate 520 0x00))
]
-r1_encode :: Benchmark
-r1_encode = bgroup "base16 encode" [
- bench "120b" $ nf R1.encodeBase16' "jtobin was here"
- , bench "240b" $ nf R1.encodeBase16' "jtobin was herebenching stuff."
+encode_various :: Benchmark
+encode_various = bgroup "base16" [
+ bench "1024B input" $ nf B16.encode (BS.replicate 1024 0x00)
+ , bench "1023B input" $ nf B16.encode (BS.replicate 1023 0x00)
+ , bench "1022B input" $ nf B16.encode (BS.replicate 1022 0x00)
]
-
-r1_decode :: Benchmark
-r1_decode = bgroup "base16 decode" [
- bench "120b" $ nf R1.decodeBase16Untyped "6a746f62696e207761732068657265"
- , bench "240b" $ nf R1.decodeBase16Untyped
- "6a746f62696e20776173206865726562656e6368696e672073747566662e"
- ]
-
-suite :: Benchmark
-suite = bgroup "benchmarks" [
- bgroup "ppad-base16" [
- base16_encode
- , base16_encode'
- , base16_decode
- -- ]
- --, bgroup "base16-bytestring" [
- -- r0_encode
- -- , r0_decode
- -- ]
- --, bgroup "base16" [
- -- r1_encode
- -- , r1_decode
- ]
- ]
-
diff --git a/bench/Weight.hs b/bench/Weight.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE PackageImports #-}
+
+module Main where
+
+import qualified Data.ByteString as BS
+import qualified "base16-bytestring" Data.ByteString.Base16 as R0
+import qualified "base16" Data.ByteString.Base16 as R1
+import qualified "ppad-base16" Data.ByteString.Base16 as B16
+import qualified Weigh as W
+
+inp :: BS.ByteString
+inp = "jtobin was here benching stuffjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin was here benching stufjtobin w"
+
+hinp :: BS.ByteString
+hinp = B16.encode inp
+
+main :: IO ()
+main = W.mainWith $ do
+ W.func "ppad-base16 (encode)" B16.encode inp
+ W.func "base16-bytestring (encode)" R0.encode inp
+ W.func "base16 (encode)" R1.encodeBase16' inp
+
+ W.func "ppad-base16 (decode)" B16.decode hinp
+ W.func "base16-bytestring (decode)" R0.decode hinp
+ W.func "base16 (decode)" R1.decodeBase16Untyped inp
diff --git a/ppad-base16.cabal b/ppad-base16.cabal
@@ -43,6 +43,7 @@ test-suite base16-tests
, bytestring
, ppad-base16
, tasty
+ , tasty-hunit
, tasty-quickcheck
benchmark base16-bench
@@ -62,3 +63,21 @@ benchmark base16-bench
, criterion
, ppad-base16
+benchmark base16-weigh
+ type: exitcode-stdio-1.0
+ default-language: Haskell2010
+ hs-source-dirs: bench
+ main-is: Weight.hs
+
+ ghc-options:
+ -rtsopts -O2 -Wall
+
+ build-depends:
+ base
+ , base16
+ , base16-bytestring
+ , bytestring
+ , criterion
+ , ppad-base16
+ , weigh
+
diff --git a/test/Main.hs b/test/Main.hs
@@ -1,5 +1,20 @@
+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE PackageImports #-}
module Main where
+import qualified "ppad-base16" Data.ByteString.Base16 as B16
+import Test.Tasty
+import Test.Tasty.HUnit
+
main :: IO ()
-main = pure ()
+main = defaultMain $ testGroup "base16" [ tests ]
+
+pec = "6a746f62696e2077617320686572652062656e6368696e67207374756666"
+inp = "jtobin was here benching stuff"
+
+tests = testGroup "base16" [
+ testCase "encode" $ assertEqual mempty pec (B16.encode inp)
+ ]
+