-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The code decode function is `decodeAddrStateAllowLeftoverT` and we bench this via `decodeAddrEither`. Run this with `cabal bench addr`.
- Loading branch information
Showing
2 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
import Cardano.Ledger.Crypto (StandardCrypto) | ||
import Cardano.Ledger.Address (Addr, decodeAddrEither, serialiseAddr) | ||
|
||
import Control.Monad (replicateM) | ||
|
||
import Criterion (Benchmark, env, bench, nf) | ||
import Criterion.Main (defaultMain) | ||
|
||
import Data.ByteString.Char8 (ByteString) | ||
import Data.Either (lefts) | ||
|
||
import Test.Cardano.Ledger.Core.Arbitrary () | ||
import Test.QuickCheck (arbitrary, generate) | ||
|
||
main :: IO () | ||
main = do | ||
defaultMain $ | ||
map (\c -> env (generateAddrAsBytestring c) decodeAddrBench) (map (* 500) [1 .. 2]) | ||
where | ||
decodeAddrBench :: [ByteString] -> Benchmark | ||
decodeAddrBench xs = | ||
bench ("decodeAddr (" ++ show (length xs) ++ ")") (nf tryDecodeAddr xs) | ||
|
||
-- ------------------------------------------------------------------------------------------------- | ||
|
||
generateAddrAsBytestring :: Int -> IO [ByteString] | ||
generateAddrAsBytestring count = | ||
replicateM count (serialiseAddr <$> genAddr) | ||
where | ||
genAddr :: IO (Addr StandardCrypto) | ||
genAddr = generate arbitrary | ||
|
||
tryDecodeAddr :: [ByteString] -> () | ||
tryDecodeAddr xs = | ||
case lefts $ map decode xs of | ||
[] -> () | ||
ys -> error $ "tryDecodeAddr: " ++ show ys | ||
where | ||
decode :: ByteString -> Either String (Addr StandardCrypto) | ||
decode = decodeAddrEither |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters