export benchmark to json

This commit is contained in:
Seungheon Oh 2022-05-24 16:10:12 -05:00
parent 5eebba1355
commit 35ba59c5d6
4 changed files with 39 additions and 17 deletions

View file

@ -1,6 +1,7 @@
module Bench (Benchmark (..), benchmarkScript, specificationTreeToBenchmarks) where module Bench (Benchmark (..), benchmarkScript, specificationTreeToBenchmarks) where
import Codec.Serialise (serialise) import Codec.Serialise (serialise)
import Data.Aeson hiding (Success)
import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy qualified as LBS
import Data.ByteString.Short qualified as SBS import Data.ByteString.Short qualified as SBS
import Data.List (intercalate) import Data.List (intercalate)
@ -35,6 +36,23 @@ data Benchmark = Benchmark
} }
deriving stock (Show, Eq, Ord) deriving stock (Show, Eq, Ord)
instance FromJSON Benchmark where
parseJSON (Object v) =
Benchmark <$> v .: "name"
<*> v .: "cpu"
<*> v .: "mem"
<*> v .: "size"
parseJSON _ = mempty
instance ToJSON Benchmark where
toJSON (Benchmark name cpu mem size) =
object
[ "name" .= name
, "cpu" .= cpu
, "mem" .= mem
, "size" .= size
]
benchmarkScript :: String -> Script -> Benchmark benchmarkScript :: String -> Script -> Benchmark
benchmarkScript name script = Benchmark (pack name) cpu mem size benchmarkScript name script = Benchmark (pack name) cpu mem size
where where

View file

@ -1,6 +1,8 @@
module Main (main) where module Main (main) where
import Bench (specificationTreeToBenchmarks) import Bench (specificationTreeToBenchmarks)
import Data.Aeson.Text (encodeToLazyText)
import Data.Text.Lazy.IO as I
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
@ -15,19 +17,20 @@ import Prelude
main :: IO () main :: IO ()
main = do main = do
mapM_ print $ I.writeFile "bench.json" $
specificationTreeToBenchmarks $ encodeToLazyText $
group specificationTreeToBenchmarks $
"Benchmark" group
[ group "Benchmark"
"Effects" [ group
[ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs "Effects"
, group "Governor Mutation Effect" GovernorMutation.specs [ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
] , group "Governor Mutation Effect" GovernorMutation.specs
, group "Stake" Stake.specs ]
, group "Proposal" Proposal.specs , group "Stake" Stake.specs
, group "AuthorityToken" AuthorityToken.specs , group "Proposal" Proposal.specs
, group "Treasury" Treasury.specs , group "AuthorityToken" AuthorityToken.specs
, group "AuthorityToken" AuthorityToken.specs , group "Treasury" Treasury.specs
, group "Governor" Governor.specs , group "AuthorityToken" AuthorityToken.specs
] , group "Governor" Governor.specs
]

View file

@ -50,7 +50,7 @@ exists s (Group name st) = or (exists s <$> st) || s == name
group :: String -> [SpecificationTree] -> SpecificationTree group :: String -> [SpecificationTree] -> SpecificationTree
group name st group name st
| or $ exists name <$> st = error "Name already exists" | or $ exists name <$> st = error $ "Name already exists: " <> name
| otherwise = Group name st | otherwise = Group name st
getSpecification :: String -> SpecificationTree -> Maybe Specification getSpecification :: String -> SpecificationTree -> Maybe Specification

1
bench.json Normal file
View file

@ -0,0 +1 @@
[{"cpu":340268715,"mem":724428,"name":"Benchmark/Effects/Treasury Withdrawal Effect/effect/Simple","size":3050},{"cpu":570029812,"mem":1211300,"name":"Benchmark/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries ","size":3377},{"cpu":502351827,"mem":1071087,"name":"Benchmark/Effects/Treasury Withdrawal Effect/effect/Mixed Assets","size":3242},{"cpu":103054094,"mem":227264,"name":"Benchmark/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass","size":7467},{"cpu":126696096,"mem":263635,"name":"Benchmark/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass","size":3293},{"cpu":147898986,"mem":329450,"name":"Benchmark/Stake/policy/stakeCreation","size":2265},{"cpu":261845190,"mem":576377,"name":"Benchmark/Stake/validator/stakeDepositWithdraw deposit","size":3829},{"cpu":261845190,"mem":576377,"name":"Benchmark/Stake/validator/stakeDepositWithdraw withdraw","size":3821},{"cpu":34571405,"mem":70066,"name":"Benchmark/Proposal/policy/proposalCreation","size":1549},{"cpu":242652509,"mem":511783,"name":"Benchmark/Proposal/validator/cosignature/proposal","size":5247},{"cpu":183513647,"mem":395070,"name":"Benchmark/Proposal/validator/cosignature/stake","size":4366},{"cpu":240358004,"mem":492704,"name":"Benchmark/Proposal/validator/voting/proposal","size":5255},{"cpu":154841851,"mem":329311,"name":"Benchmark/Proposal/validator/voting/stake","size":4419},{"cpu":25177457,"mem":55883,"name":"Benchmark/AuthorityToken/singleAuthorityTokenBurned/Correct simple","size":806},{"cpu":40266637,"mem":88241,"name":"Benchmark/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs","size":900},{"cpu":37343572,"mem":79744,"name":"Benchmark/Treasury/Validator/Positive/Allows for effect changes","size":1841},{"cpu":25177457,"mem":55883,"name":"Benchmark/AuthorityToken/singleAuthorityTokenBurned/Correct simple","size":806},{"cpu":40266637,"mem":88241,"name":"Benchmark/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs","size":900},{"cpu":57648280,"mem":119961,"name":"Benchmark/Governor/policy/GST minting","size":1836},{"cpu":309839049,"mem":649395,"name":"Benchmark/Governor/validator/proposal creation","size":7994},{"cpu":429394828,"mem":928681,"name":"Benchmark/Governor/validator/GATs minting","size":8113},{"cpu":100243054,"mem":221538,"name":"Benchmark/Governor/validator/mutate governor state","size":7540}]