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 {..}) =

View file

@ -3,7 +3,9 @@ module Main (main) where
import Bench (specificationTreeToBenchmarks)
import Data.Csv (encodeDefaultOrderedByName)
import Data.Text.Lazy.Encoding (decodeUtf8)
import Data.Text.Lazy.IO as I
import Data.Text.Lazy.IO as I (writeFile)
import Prettyprinter (defaultLayoutOptions, layoutPretty, pretty)
import Prettyprinter.Render.String (renderString)
import Spec.AuthorityToken qualified as AuthorityToken
import Spec.Effect.GovernorMutation qualified as GovernorMutation
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
@ -21,7 +23,7 @@ main = do
I.writeFile "bench.csv" $
(decodeUtf8 . encodeDefaultOrderedByName) res
mapM_ (Prelude.putStrLn . (<> "\n") . show) res
mapM_ (putStrLn . renderString . layoutPretty defaultLayoutOptions . pretty) res
where
res =
specificationTreeToBenchmarks $