pretty printer
This commit is contained in:
parent
7457c6334b
commit
35d758fcde
2 changed files with 18 additions and 7 deletions
|
|
@ -8,7 +8,7 @@ import Data.ByteString.Short qualified as SBS
|
||||||
import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=))
|
import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=))
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import Data.Text (Text, pack, unpack)
|
import Data.Text (Text, pack)
|
||||||
import GHC.Generics (Generic)
|
import GHC.Generics (Generic)
|
||||||
import Plutus.V1.Ledger.Api (
|
import Plutus.V1.Ledger.Api (
|
||||||
ExBudget (ExBudget),
|
ExBudget (ExBudget),
|
||||||
|
|
@ -17,6 +17,7 @@ import Plutus.V1.Ledger.Api (
|
||||||
Script,
|
Script,
|
||||||
)
|
)
|
||||||
import Plutus.V1.Ledger.Api qualified as Plutus
|
import Plutus.V1.Ledger.Api qualified as Plutus
|
||||||
|
import Prettyprinter (Pretty (pretty), indent, vsep)
|
||||||
|
|
||||||
import Spec.Specification (
|
import Spec.Specification (
|
||||||
Specification (Specification),
|
Specification (Specification),
|
||||||
|
|
@ -37,11 +38,19 @@ data Benchmark = Benchmark
|
||||||
, scriptSize :: Int
|
, scriptSize :: Int
|
||||||
-- ^ The on-chain size of a script.
|
-- ^ The on-chain size of a script.
|
||||||
}
|
}
|
||||||
deriving stock (Eq, Ord, Generic)
|
deriving stock (Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
instance Show Benchmark where
|
instance Pretty Benchmark where
|
||||||
show (Benchmark name (ExCPU cpu) (ExMemory mem) size) =
|
pretty (Benchmark name (ExCPU (toInteger -> cpu)) (ExMemory (toInteger -> mem)) size) =
|
||||||
unpack name <> "\n\tCPU: " <> show cpu <> " MEM: " <> show mem <> " SIZE: " <> show size
|
vsep
|
||||||
|
[ pretty name
|
||||||
|
, indent 4 $
|
||||||
|
vsep
|
||||||
|
[ "CPU: " <> pretty cpu
|
||||||
|
, "MEM: " <> pretty mem
|
||||||
|
, "SIZE: " <> pretty size
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
instance ToNamedRecord Benchmark where
|
instance ToNamedRecord Benchmark where
|
||||||
toNamedRecord (Benchmark {..}) =
|
toNamedRecord (Benchmark {..}) =
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ module Main (main) where
|
||||||
import Bench (specificationTreeToBenchmarks)
|
import Bench (specificationTreeToBenchmarks)
|
||||||
import Data.Csv (encodeDefaultOrderedByName)
|
import Data.Csv (encodeDefaultOrderedByName)
|
||||||
import Data.Text.Lazy.Encoding (decodeUtf8)
|
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.AuthorityToken qualified as AuthorityToken
|
||||||
import Spec.Effect.GovernorMutation qualified as GovernorMutation
|
import Spec.Effect.GovernorMutation qualified as GovernorMutation
|
||||||
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
|
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
|
||||||
|
|
@ -21,7 +23,7 @@ main = do
|
||||||
I.writeFile "bench.csv" $
|
I.writeFile "bench.csv" $
|
||||||
(decodeUtf8 . encodeDefaultOrderedByName) res
|
(decodeUtf8 . encodeDefaultOrderedByName) res
|
||||||
|
|
||||||
mapM_ (Prelude.putStrLn . (<> "\n") . show) res
|
mapM_ (putStrLn . renderString . layoutPretty defaultLayoutOptions . pretty) res
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
specificationTreeToBenchmarks $
|
specificationTreeToBenchmarks $
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue