pretty printer

This commit is contained in:
Seungheon Oh 2022-05-26 09:37:41 -05:00
parent 7457c6334b
commit 35d758fcde
No known key found for this signature in database
GPG key ID: 9B0E12D357369B66
2 changed files with 18 additions and 7 deletions

View file

@ -8,7 +8,7 @@ import Data.ByteString.Short qualified as SBS
import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=))
import Data.List (intercalate)
import Data.Maybe (fromJust)
import Data.Text (Text, pack, unpack)
import Data.Text (Text, pack)
import GHC.Generics (Generic)
import Plutus.V1.Ledger.Api (
ExBudget (ExBudget),
@ -17,6 +17,7 @@ import Plutus.V1.Ledger.Api (
Script,
)
import Plutus.V1.Ledger.Api qualified as Plutus
import Prettyprinter (Pretty (pretty), indent, vsep)
import Spec.Specification (
Specification (Specification),
@ -37,11 +38,19 @@ data Benchmark = Benchmark
, scriptSize :: Int
-- ^ The on-chain size of a script.
}
deriving stock (Eq, Ord, Generic)
deriving stock (Show, Eq, Ord, Generic)
instance Show Benchmark where
show (Benchmark name (ExCPU cpu) (ExMemory mem) size) =
unpack name <> "\n\tCPU: " <> show cpu <> " MEM: " <> show mem <> " SIZE: " <> show size
instance Pretty Benchmark where
pretty (Benchmark name (ExCPU (toInteger -> cpu)) (ExMemory (toInteger -> mem)) size) =
vsep
[ pretty name
, indent 4 $
vsep
[ "CPU: " <> pretty cpu
, "MEM: " <> pretty mem
, "SIZE: " <> pretty size
]
]
instance ToNamedRecord Benchmark where
toNamedRecord (Benchmark {..}) =