Commit b3e3fb74 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Actually commit benchmarks

I forgot to add them earlier, no idea why CI didn't break...
parent 8182aa5a
module Main where
import Criterion.Main
import qualified BenchMorphParser as MorphParser
main :: IO ()
main = defaultMain
[ MorphParser.benchmarks
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module BenchMorphParser (benchmarks) where
import Criterion
import qualified Data.List.NonEmpty as NonEmpty
import Data.Text (Text)
import Control.DeepSeq
import MA.Coalgebra.Parser
import MA.Coalgebra.RefinementTypes
import MA.FunctorExpression.Sorts
import MA.FunctorExpression.Type
import MA.FunctorExpression.Parser
import MA.Functors.Polynomial
import MA.Functors
benchmarks :: Benchmark
benchmarks = bgroup "Morphism Parser"
[ benchIdentity
, benchMarkov
benchIdentity :: Benchmark
benchIdentity = bgroup "Identity" $
let f = (Functor 1 (mkPoly [[Identity Variable]]))
[ benchParser "simple" f "x: y\ny: z\nz: x"
, benchParser "predefined" f "x: x\ny: y\nz: z"
benchMarkov :: Benchmark
benchMarkov = bgroup "Ax(R^X)" $
let Right f = annotateSorts <$> parseFunctorExpression registeredFunctors "" "{a,b,c,d,e}x(R^X)"
[ benchParser "simple" f
"x: (a, {x: 0.5, y: 0.5})\n\
\y: (b, {y: 0.7, x: 0.2, z: 0.1})\n\
\z: (c, {z: 1.0})"
benchParser ::
(Functor f, ParseMorphism f, NFData (Label f), NFData (H1 f))
=> String
-> FunctorExpression f Sort
-> Text
-> Benchmark
benchParser name fexpr input = bench name (nf parse input)
parse = parseMorphisms fexpr ""
mkPoly :: [[Factor a]] -> Polynomial a
mkPoly =
Polynomial . Sum . NonEmpty.fromList . map (Product . NonEmpty.fromList)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment