From 8f645e5ab87e7029d9cdf926ff9f6fe94a85948c Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita Date: Thu, 6 Jul 2023 00:00:31 +0100 Subject: [PATCH] Improve and fix benchmarking suite --- BENCHMARKING.md | 9 +++++++++ baseline.csv | 7 +++++++ hegg.cabal | 7 +++++-- test/Bench.hs | 37 +++++++++++++++++++++++++++++++------ test/Sym.hs | 7 +++++-- 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 BENCHMARKING.md create mode 100644 baseline.csv diff --git a/BENCHMARKING.md b/BENCHMARKING.md new file mode 100644 index 0000000..e143465 --- /dev/null +++ b/BENCHMARKING.md @@ -0,0 +1,9 @@ +### Comparing benchmarks against baselines +``` +cabal bench --benchmark-options="+RTS -T -RTS --baseline baseline.csv" +``` + +### Saving new baselines +``` +cabal bench --benchmark-options="+RTS -T -RTS --csv baseline.csv" +``` diff --git a/baseline.csv b/baseline.csv new file mode 100644 index 0000000..c5856ac --- /dev/null +++ b/baseline.csv @@ -0,0 +1,7 @@ +Name,Mean (ps),2*Stdev (ps),Allocated,Copied,Peak Memory +All.Tests.Symbolic bench.i1,30148987500,1892104820,108977098,5670033,42991616 +All.Tests.Symbolic bench.i2,32330562500,2040971046,111012444,5925886,42991616 +All.Tests.Symbolic bench.i3,55056050000,4438483130,199744799,17062413,50331648 +All.Tests.Symbolic bench.i4,37195237500,2147631488,133168692,9604120,50331648 +All.Tests.Symbolic bench.i5,28361087500,1849731332,104740735,5986935,50331648 +All.Tests.Symbolic bench.i6,28716525000,2002342972,102315060,5563405,50331648 diff --git a/hegg.cabal b/hegg.cabal index 3f6f9d8..4cda6ea 100644 --- a/hegg.cabal +++ b/hegg.cabal @@ -129,8 +129,11 @@ benchmark hegg-bench tasty, tasty-hunit, tasty-quickcheck, - tasty-bench >= 0.2 && < 0.4 - ghc-options: -with-rtsopts=-A32m -threaded + tasty-bench >= 0.2, + deepseq + ghc-options: -with-rtsopts=-A32m + if impl(ghc >= 8.6) + ghc-options: -fproc-alignment=64 Flag vizdot Description: Compile 'Data.Equality.Graph.Dot' module to visualize e-graphs diff --git a/test/Bench.hs b/test/Bench.hs index 58b6f98..48cd6c5 100644 --- a/test/Bench.hs +++ b/test/Bench.hs @@ -1,18 +1,43 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE StandaloneDeriving, FlexibleInstances, DeriveAnyClass, RankNTypes, QuantifiedConstraints, UndecidableInstances, DeriveGeneric #-} import Test.Tasty.Bench +import GHC.Generics +import Control.DeepSeq + import Data.Equality.Utils import Invariants import Sym -import Lambda -import SimpleSym + +-- Instances for benchmarking. It's amazing this works! +deriving instance (forall a. Generic a => Generic (f a)) => Generic (Fix f) +deriving instance NFData UOp +deriving instance NFData BOp +deriving instance NFData a => NFData (Expr a) +deriving instance (forall a. NFData a => NFData (f a), forall a. Generic a => Generic (f a)) => NFData (Fix f) tests :: [Benchmark] tests = [ bgroup "Tests" - [ symTests - , lambdaTests - , simpleSymTests - , invariants + [ bgroup "Symbolic bench" + [ bench "i1" $ + nf rewrite (Fix $ BinOp Integral 1 "x") + + , bench "i2" $ + nf rewrite (Fix $ BinOp Integral (Fix $ UnOp Cos "x") "x") + + , bench "i3" $ + nf rewrite (Fix $ BinOp Integral (Fix $ BinOp Pow "x" 1) "x") + + , bench "i4" $ + nf rewrite (_i ((*) "x" (_cos "x")) "x") + + , bench "i5" $ + nf rewrite (_i ((*) (_cos "x") "x") "x") + + , bench "i6" $ + nf rewrite (_i (_ln "x") "x") + ] + -- , invariants ] ] main :: IO () diff --git a/test/Sym.hs b/test/Sym.hs index e926313..ad4f08a 100644 --- a/test/Sym.hs +++ b/test/Sym.hs @@ -6,8 +6,10 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveGeneric #-} module Sym where +import GHC.Generics import Test.Tasty import Test.Tasty.HUnit @@ -35,6 +37,7 @@ data Expr a = Sym !String | BinOp !BOp !a !a deriving ( Eq, Ord, Show , Functor, Foldable, Traversable + , Generic ) data BOp = Add | Sub @@ -43,13 +46,13 @@ data BOp = Add | Pow | Diff | Integral - deriving (Eq, Ord, Show) + deriving (Eq, Ord, Show, Generic) data UOp = Sin | Cos | Sqrt | Ln - deriving (Eq, Ord, Show) + deriving (Eq, Ord, Show, Generic) instance IsString (Fix Expr) where fromString = Fix . Sym