-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #884 from input-output-hk/abailly-iohk/micro-bench…
…marks Add micro benchmarks for serialising and applying Transactions
- Loading branch information
Showing
8 changed files
with
80 additions
and
6 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
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,6 @@ | ||
# Ledger micro-benchmarks | ||
|
||
These micro-benchmarks details the time for various key aspects of applying transactions in the Cardano ledger in a Hydra Head. | ||
The absolute values are relatively meaningless, what's important is the relative cost of the various operations involved in the end-to-end process of submitting a new transaction to a Hydra Head and applying it to the ledger. | ||
|
||
* :chart_with_upwards_trend: [Ledger Benchmarks](pathname:///ledger-bench.html) |
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 OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main where | ||
|
||
import Hydra.Prelude | ||
|
||
import qualified Data.Aeson as Aeson | ||
import Criterion (bench, bgroup, whnf, nf) | ||
import Criterion.Main (defaultMain) | ||
import Hydra.Cardano.Api ( | ||
UTxO, serialiseToCBOR, | ||
) | ||
import Hydra.Ledger (ChainSlot (ChainSlot), Ledger (applyTransactions), ValidationError) | ||
import Hydra.Ledger.Cardano (Tx, cardanoLedger, genFixedSizeSequenceOfSimplePaymentTransactions) | ||
import Test.QuickCheck (generate) | ||
import Hydra.API.ClientInput (ClientInput(NewTx)) | ||
import Data.Aeson ((.=), object, Value(String)) | ||
import qualified Data.List as List | ||
import Hydra.Chain.Direct.Fixture (defaultGlobals, defaultLedgerEnv) | ||
|
||
main :: IO () | ||
main = do | ||
(utxo, tx) <- prepareTx | ||
let jsonNewTx = (Aeson.encode . NewTx) tx | ||
toNewTx bs = object [ "tag" .= ("NewTx" :: Text), "transaction" .= String (decodeUtf8 bs) ] | ||
cborNewTx = (Aeson.encode . toNewTx . serialiseToCBOR) tx | ||
defaultMain | ||
[ bgroup | ||
"Cardano Ledger" | ||
[ bench "Apply Tx" $ whnf benchApplyTxs (utxo, tx) | ||
, bench "Serialize NewTx (JSON)" $ nf (Aeson.encode . NewTx) tx | ||
, bench "Serialize NewTx (CBOR)" $ nf serialiseToCBOR tx | ||
, bench "Deserialize NewTx (JSON)" $ whnf (Aeson.decode @(ClientInput Tx)) jsonNewTx | ||
, bench "Deserialize NewTx (CBOR-in-JSON)" $ whnf (Aeson.decode @(ClientInput Tx)) cborNewTx | ||
] | ||
] | ||
|
||
prepareTx :: IO (UTxO, Tx) | ||
prepareTx = | ||
second List.head <$> generate (genFixedSizeSequenceOfSimplePaymentTransactions 1) | ||
|
||
benchApplyTxs :: (UTxO, Tx) -> Either (Tx, ValidationError) UTxO | ||
benchApplyTxs (utxo, tx) = applyTransactions defaultLedger (ChainSlot 1) utxo [tx] | ||
|
||
defaultLedger :: Ledger Tx | ||
defaultLedger = cardanoLedger defaultGlobals defaultLedgerEnv |
File renamed without changes.
File renamed without changes.
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
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
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