@@ -13,6 +13,9 @@ import HhiReducer
1313import Control.Monad.Fix ( fix )
1414import BenchmarkSources
1515import MicroHsExp ( toMhsPrg )
16+ import qualified MicroHs.Main as MHS (main )
17+ import System.Environment (withArgs )
18+ import System.IO (readFile' )
1619import MhsEval
1720
1821loadTestCase :: SourceCode -> IO CL
@@ -72,7 +75,15 @@ reducerTestLog expr = show $ transLinkLog primitives expr
7275microHsTest :: MhsContext -> String -> IO ()
7376microHsTest ctx prg = run ctx prg
7477
75-
78+ microHsCompile :: FilePath -> IO String
79+ microHsCompile fileName = do
80+ -- use microHs to compile file fileName to 'out.comb'
81+ withArgs [fileName] MHS. main
82+ -- return the program 'out.comb' as a string
83+ content <- readFile' " out.comb"
84+ -- deleteFile "out.comb"
85+ return content
86+
7687benchmarks :: IO ()
7788benchmarks = do
7889 fac <- loadTestCase factorial
@@ -107,6 +118,11 @@ benchmarks = do
107118 mhsFibEta = toMhsPrg fibEta
108119 mhsAckEta = toMhsPrg akkEta
109120
121+ -- prepare MicroHs programs
122+ mhsFib <- microHsCompile " benchmark/Fib.mhs"
123+ mhsAkk <- microHsCompile " benchmark/Akk.mhs"
124+ mhsTak <- microHsCompile " benchmark/Tak.mhs"
125+
110126 print facEta
111127 print takEta
112128 print fibEta
@@ -130,19 +146,19 @@ benchmarks = do
130146 -- , bench "factorial Graph-Reduce-Lin" $ nf graphTest facBulkLinear
131147 -- , bench "factorial Graph-Reduce-Log" $ nf graphTest facBulkLog
132148 -- , bench "factorial HHI-Reduce" $ nf reducerTest fac
133- bench " factorial HHI-Eta" $ nf reducerTest facEta
149+ -- bench "factorial HHI-Eta" $ nf reducerTest facEta
134150 -- , bench "factorial HHI-Bulk" $ nf reducerTest facBulk
135151 -- , bench "factorial HHI-Bulk-Log" $ nf reducerTestLog facBulk
136152 -- , bench "factorial HHI-Break-Bulk" $ nf reducerTest facBulkLinear
137153 -- , bench "factorial HHI-Break-Log" $ nf reducerTestLog facBulkLog
138- , bench " factorial MicroHs" $ nfIO (microHsTest mhsContext mhsFacEta)
139- , bench " factorial Native" $ nf fact 10
154+ -- , bench "factorial MicroHs" $ nfIO (microHsTest mhsContext mhsFacEta)
155+ -- , bench "factorial Native" $ nf fact 10
140156 -- bench "fibonacci Graph-Reduce" $ nf graphTest fib
141157 -- , bench "fibonacci Graph-Reduce-Eta" $ nf graphTest fibEta
142158 -- , bench "fibonacci Graph-Reduce-Lin" $ nf graphTest fibBulkLinear
143159 -- , bench "fibonacci Graph-Reduce-Log" $ nf graphTest fibBulkLog
144160 -- , bench "fibonacci HHI-Reduce" $ nf reducerTest fib
145- , bench " fibonacci HHI-Eta" $ nf reducerTest fibEta
161+ bench " fibonacci HHI-Eta" $ nf reducerTest fibEta
146162 -- , bench "fibonacci HHi-Bulk" $ nf reducerTest fibBulk
147163 -- , bench "fibonacci HHI-Bulk-Log" $ nf reducerTestLog fibBulk
148164 -- , bench "fibonacci HHI-Break-Bulk" $ nf reducerTest fibBulkLinear
@@ -153,6 +169,7 @@ benchmarks = do
153169 -- , bench "ackermann Graph-Reduce-Eta" $ nf graphTest akkEta
154170 -- , bench "ackermann Graph-Reduce-Lin" $ nf graphTest akkBulkLinear
155171 -- , bench "ackermann Graph-Reduce-Log" $ nf graphTest akkBulkLog
172+ , bench " fibonacci MHS Haskell" $ nfIO (microHsTest mhsContext mhsFib)
156173 , bench " ackermann HHI-Reduce" $ nf reducerTest akkEta
157174 -- , bench "ackermann HHI-Eta" $ nf reducerTest akkEta
158175 -- , bench "ackermann HHI-Bulk" $ nf reducerTest akkBulk
@@ -173,13 +190,15 @@ benchmarks = do
173190 -- , bench "tak Graph-Reduce-Lin" $ nf graphTest takBulkLinear
174191 -- , bench "tak Graph-Reduce-Log" $ nf graphTest takBulkLog
175192 -- , bench "tak HHI-Reduce" $ nf reducerTest tak
193+ , bench " ackermann MHS Haskell" $ nfIO (microHsTest mhsContext mhsAkk)
176194 , bench " tak HHI-Eta" $ nf reducerTest takEta
177195 -- , bench "tak HHI-Bulk" $ nf reducerTest takBulk
178196 -- , bench "tak HHI-Bulk-Log" $ nf reducerTestLog takBulk
179197 -- , bench "tak HHI-Break-Bulk" $ nf reducerTest takBulkLinear
180198 -- , bench "tak HHI-Break-Log" $ nf reducerTestLog takBulkLog
181199 , bench " tak MicroHs" $ nfIO (run mhsContext mhsTakEta)
182200 , bench " tak Native" $ nf tak1 (18 ,6 ,3 )
201+ , bench " tak MHS Haskell" $ nfIO (microHsTest mhsContext mhsTak)
183202 ]
184203 closeMhsContext mhsContext
185204 putStrLn " Benchmarks completed."
@@ -214,6 +233,9 @@ tak_18_6 :: Int -> Int
214233tak_18_6 = takN 18 6
215234
216235takN :: Int -> Int -> Int -> Int
217- takN = fix (\ f x y z -> (if y >= x then z else f (f (x- 1 ) y z) (f (y- 1 ) z x) (f (z- 1 ) x y )))
236+ takN = fix (\ f x y z ->
237+ if y >= x
238+ then z
239+ else f (f (x- 1 ) y z) (f (y- 1 ) z x) (f (z- 1 ) x y ))
218240
219241tak1 (x,y,z) = takN x y z
0 commit comments