Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 19, 2024
1 parent 03576af commit e564393
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions benchmarks/Main.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
module Main where
import Test.Tasty.Bench ( bench, bgroup, defaultMain, nf )
import Test.Tasty.Bench ( bench, bgroup, defaultMain, nf, whnf )
import Math.Algebra.Hspray
import qualified Algebra.Additive as AlgAdd
import qualified Algebra.Ring as AlgRing
import Number.Ratio ( (%), T ( (:%) ) )

f :: Integer -> RatioOfQPolynomials
f n = ((a AlgRing.^ 8 AlgAdd.- AlgRing.one) ^/^ (a AlgAdd.- AlgRing.one)) AlgRing.^ n AlgAdd.+
(a AlgAdd.+ AlgRing.one) :% a
where
a = outerQVariable

g :: Integer -> RatioOfQSprays
g n = ((x^**^8 ^-^ unitSpray) %//% (x ^-^ unitSpray)) AlgRing.^ n AlgAdd.+
RatioOfSprays (x ^+^ unitSpray) x
where
x = qlone 1

fibo :: Int -> Integer
fibo n = if n < 2 then toInteger n else fibo (n - 1) + fibo (n - 2)
Expand All @@ -21,10 +37,10 @@ combn2' n = zip [0 .. n-2] (zip row1 row2)
main :: IO ()
main =
defaultMain
[ bgroup "combn2"
[ bench "combn2 - 20" $ nf combn2 20
, bench "combn2' - 20" $ nf combn2' 20
, bench "combn2 - 100" $ nf combn2 100
, bench "combn2' - 100" $ nf combn2' 100
[ bgroup "ratios"
[ bench "f 2" $ whnf f 2
, bench "g 2" $ whnf g 2
, bench "f 5" $ whnf f 5
, bench "g 5" $ whnf g 5
]
]
1 change: 1 addition & 0 deletions hspray.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ benchmark benchmarks
hs-source-dirs: benchmarks/
Build-Depends: base >= 4.7 && < 5
, tasty-bench >= 0.3 && < 0.4
, numeric-prelude >= 0.4.4 && < 0.5
, hspray
ghc-options: "-with-rtsopts=-A32m"
if impl(ghc >= 8.6)
Expand Down

0 comments on commit e564393

Please sign in to comment.