commit 194569f64ff8485e0a2e537079a82b9a52c74bd1
parent dd25247ba61d75fae3502b51e95766acf47450e4
Author: Jared Tobin <jared@jtobin.io>
Date: Fri, 3 Jan 2025 19:38:59 -0330
bench: add decode
Diffstat:
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
@@ -41,7 +41,7 @@ Haddocks (API documentation, etc.) are hosted at
The aim is best-in-class performance for pure, highly-auditable Haskell
code. At present we're slightly faster than the official BIP173
-reference implementation.
+reference implementation due to more efficient base32 conversion.
Current benchmark figures on my mid-2020 MacBook Air look like (use
`cabal bench` to run the benchmark suite):
diff --git a/bench/Main.hs b/bench/Main.hs
@@ -21,34 +21,48 @@ main = defaultMain [
suite
]
-base32 :: Benchmark
-base32 = bgroup "base32 encode" [
+base32_encode :: Benchmark
+base32_encode = bgroup "base32 encode" [
bench "120b" $ nf Base32.encode "jtobin was here"
, bench "128b (non 40-bit multiple length)" $
nf Base32.encode "jtobin was here!"
, bench "240b" $ nf Base32.encode "jtobin was herejtobin was here"
]
-bech32 :: Benchmark
-bech32 = bgroup "bech32 encode" [
+base32_decode :: Benchmark
+base32_decode = bgroup "base32 decode" [
+ bench "120b" $ nf Base32.decode "df6x7cnfdcs8wctnyp5x2un9"
+ , bench "128b (non 40-bit multiple length)" $
+ nf Base32.decode "df6x7cnfdcs8wctnyp5x2un9yy"
+ ]
+
+bech32_encode :: Benchmark
+bech32_encode = bgroup "bech32 encode" [
bench "120b" $ nf (Bech32.encode "bc") "jtobin was here"
, bench "128b (non 40-bit multiple length)" $
nf (Bech32.encode "bc") "jtobin was here!"
- , bench "240b" $ nf (Bech32.encode "bc") "jtobin was herejtobin was here"
+ ]
+
+bech32_decode :: Benchmark
+bech32_decode = bgroup "bech32 decode" [
+ bench "120b" $ nf Bech32.decode "bc1df6x7cnfdcs8wctnyp5x2un9f0pw8y"
+ , bench "128b (non 40-bit multiple length)" $
+ nf Bech32.decode "bc1df6x7cnfdcs8wctnyp5x2un9yyg90e5y"
]
suite :: Benchmark
-suite = env setup $ \ ~(a, b, c) -> bgroup "benchmarks" [
+suite = env setup $ \ ~(a, b) -> bgroup "benchmarks" [
bgroup "ppad-bech32" [
- base32
- , bech32
+ base32_encode
+ , base32_decode
+ , bech32_encode
+ , bech32_decode
]
, bgroup "reference" [
bgroup "bech32" [
bench "120b" $ nf (R.bech32Encode "bc") a
, bench "128b (non 40-bit multiple length)" $
nf (R.bech32Encode "bc") b
- , bench "240b" $ nf (R.bech32Encode "bc") c
]
]
]
@@ -56,5 +70,4 @@ suite = env setup $ \ ~(a, b, c) -> bgroup "benchmarks" [
setup = do
let a = R.toBase32 (BS.unpack "jtobin was here")
b = R.toBase32 (BS.unpack "jtobin was here!")
- c = R.toBase32 (BS.unpack "jtobin was herejtobin was here")
- pure (a, b, c)
+ pure (a, b)