Skip to content

Commit

Permalink
add strategies benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
rudymatela committed Feb 14, 2024
1 parent cb9739f commit 5919bb7
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ eg/sort
eg/subset
eg/spec
bench/carry-on
bench/strategies
bench/self
bench/longshot
bench/ill-hit
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ EG = \
bench/ill-hit \
bench/longshot \
bench/lowtests \
bench/strategies \
bench/self \
bench/carry-on \
bench/take-drop \
Expand Down
1 change: 1 addition & 0 deletions bench/runtime/lapmatrud/bench/strategies.runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.9
74 changes: 74 additions & 0 deletions bench/strategies.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-- carryon.hs: conjuring implementations of a factorial function
--
-- Copyright (C) 2021-2024 Rudy Matela
-- Distributed under the 3-Clause BSD licence (see the file LICENSE).
import Conjure

factorial :: Int -> Int
factorial 1 = 1
factorial 2 = 2
factorial 3 = 6
factorial 4 = 24


mkStrategy :: String -> Args
mkStrategy s = args
{ rewriting = r
, requireDescent = d
, adHocRedundancy = a
, copyBindings = c
, uniqueCandidates = u
}
where
itob 0 = False
itob _ = True
[r,d,a,c,u] = map itob $
case s of
"unique candidates" -> [1,1,1,1,1]
"default" -> [1,1,1,1,0]
"without reasoning" -> [0,1,1,1,0]
"without descent" -> [1,0,1,1,0]
"without ad-hoc" -> [1,1,0,1,0]
"without copy" -> [1,1,1,0,0]
"only reasoning" -> [1,0,0,0,0]
"only descent" -> [0,1,0,0,0]
"only ad-hoc" -> [0,0,1,0,0]
"only copy" -> [0,0,0,1,0]
"only typed" -> [0,0,0,0,0]
_ -> error "unknown strategy"

conjureStrategy :: Conjurable f => String -> String -> f -> [Prim] -> IO ()
conjureStrategy name nm f prims = do
putStrLn $ "-- strategy: " ++ name
conjureWith (mkStrategy name) nm f prims

strategies :: [String]
strategies =
[ "unique candidates"
, "default"
, "without reasoning"
, "without descent"
, "without ad-hoc"
, "without copy"
, "only reasoning"
, "only descent"
, "only ad-hoc"
, "only copy"
, "only typed"
]

main :: IO ()
main = do
sequence_
[ conjureStrategy s "factorial n" factorial primitives
| s <- strategies
]

primitives :: [Prim]
primitives =
[ pr (0::Int)
, pr (1::Int)
, prim "+" ((+) :: Int -> Int -> Int)
, prim "*" ((*) :: Int -> Int -> Int)
, prim "-" ((-) :: Int -> Int -> Int)
]
165 changes: 165 additions & 0 deletions bench/strategies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
-- strategy: unique candidates
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 7 candidates of size 3
-- looking through 8 candidates of size 4
-- looking through 23 candidates of size 5
-- looking through 30 candidates of size 6
-- looking through 84 candidates of size 7
-- tested 84 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: default
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 7 candidates of size 3
-- looking through 8 candidates of size 4
-- looking through 28 candidates of size 5
-- looking through 35 candidates of size 6
-- looking through 179 candidates of size 7
-- tested 95 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: without reasoning
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 16 candidates of size 3
-- looking through 17 candidates of size 4
-- looking through 279 candidates of size 5
-- looking through 313 candidates of size 6
-- looking through 5763 candidates of size 7
-- tested 656 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: without descent
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 7 candidates of size 3
-- looking through 8 candidates of size 4
-- looking through 28 candidates of size 5
-- looking through 35 candidates of size 6
-- looking through 264 candidates of size 7
-- tested 148 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: without ad-hoc
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 6 candidates of size 2
-- looking through 9 candidates of size 3
-- looking through 18 candidates of size 4
-- looking through 31 candidates of size 5
-- looking through 59 candidates of size 6
-- looking through 183 candidates of size 7
-- tested 137 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: without copy
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 9 candidates of size 3
-- looking through 10 candidates of size 4
-- looking through 32 candidates of size 5
-- looking through 39 candidates of size 6
-- looking through 197 candidates of size 7
-- tested 107 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: only reasoning
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 6 candidates of size 2
-- looking through 12 candidates of size 3
-- looking through 24 candidates of size 4
-- looking through 47 candidates of size 5
-- looking through 82 candidates of size 6
-- looking through 354 candidates of size 7
-- tested 284 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: only descent
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 6 candidates of size 2
-- looking through 21 candidates of size 3
-- looking through 42 candidates of size 4
-- looking through 302 candidates of size 5
-- looking through 602 candidates of size 6
-- looking through 6115 candidates of size 7
-- tested 1001 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: only ad-hoc
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 18 candidates of size 3
-- looking through 19 candidates of size 4
-- looking through 289 candidates of size 5
-- looking through 323 candidates of size 6
-- looking through 6468 candidates of size 7
-- tested 1028 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: only copy
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 6 candidates of size 2
-- looking through 18 candidates of size 3
-- looking through 36 candidates of size 4
-- looking through 315 candidates of size 5
-- looking through 585 candidates of size 6
-- looking through 6915 candidates of size 7
-- tested 1876 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

-- strategy: only typed
factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 6 candidates of size 2
-- looking through 21 candidates of size 3
-- looking through 42 candidates of size 4
-- looking through 330 candidates of size 5
-- looking through 630 candidates of size 6
-- looking through 7215 candidates of size 7
-- tested 1945 candidates
factorial 0 = 1
factorial x = x * factorial (x - 1)

17 changes: 17 additions & 0 deletions mk/depend.mk
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ bench/self.o: \
src/Conjure/Conjurable.hs \
src/Conjure/Conjurable/Derive.hs \
bench/self.hs
bench/strategies: \
bench/strategies.hs \
mk/toplibs
bench/strategies.o: \
src/Conjure/Utils.hs \
src/Conjure/Red.hs \
src/Conjure/Reason.hs \
src/Conjure/Prim.hs \
src/Conjure.hs \
src/Conjure/Expr.hs \
src/Conjure/Engine.hs \
src/Conjure/Defn/Test.hs \
src/Conjure/Defn/Redundancy.hs \
src/Conjure/Defn.hs \
src/Conjure/Conjurable.hs \
src/Conjure/Conjurable/Derive.hs \
bench/strategies.hs
bench/take-drop: \
bench/take-drop.hs \
mk/toplibs
Expand Down

0 comments on commit 5919bb7

Please sign in to comment.