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
import Codec.Serialise (serialise)
import Data.Aeson hiding (Success)
import Data.ByteString.Lazy qualified as LBS
import Data.ByteString.Short qualified as SBS
import Data.List (intercalate)
@ -35,6 +36,23 @@ data Benchmark = Benchmark
}
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 name script = Benchmark (pack name) cpu mem size
where