module Benchmark where import Sequenic.CTy.Combinations import qualified ExampleCT1 import qualified ExampleCT2 import Sequenic.CTy.Types import Time import System.Directory -- Benchmark testing main :: IO() main = do { -- dir <- getCurrentDirectory ; bmdir <- return "d:/workshop/projects/CTy/v0/benchmark" ; putStrLn ("Output dir. = " ++ bmdir) ; alreadyExists <- doesDirectoryExist bmdir ; if alreadyExists then return () else createDirectory bmdir ; benchmark "benchmark-1" (bmdir ++ "/bm1") ExampleCT1.inp ExampleCT1.rules ; benchmark "benchmark-2" (bmdir ++ "/bm2") ExampleCT2.inp ExampleCT2.rules } benchmark :: String -> String -> Input -> [Rule] -> IO () benchmark name outputDir inp rules = do { putStrLn ("** Running Benchmark " ++ name ++ " ...") ; alreadyExists <- doesDirectoryExist outputDir ; if alreadyExists then return () else createDirectory outputDir ; alreadyExists <- doesDirectoryExist resultDir ; if alreadyExists then return () else createDirectory resultDir ; -- -- Minimum combinations -- writeFile summaryf ((show (nCats inp))++" categories, "++(show (nClasses inp))++" classes, "++(show (nCombs inp))++" possible combinations\n") ; t1 <- getClockTime ; suite <- getMinComb ; writeFile (resultDir ++ "/Minimal Combination.txt") (showSuite suite) ; t2 <- getClockTime ; appendFile summaryf ("\nMinimal Combination ("++(show (length (suite)))++" combinations)\n"++(showTimeDifference (diffClockTimes t2 t1))) ; putStrLn "Finished Minimal" ; -- -- Min-rules combinations -- clockMinRules rules 1 ; putStrLn "Finished Minimal Ruled" ; -- -- Full-rules combinations -- clockFullRules rules 1 ; putStrLn "Finished Full Ruled" ; -- -- Full combinations -- t1 <- getClockTime ; suite <- getFullComb ; writeFile (resultDir ++ "/Full Combination.txt") (showSuite suite) ; t2 <- getClockTime ; appendFile summaryf ("\nFull Combination ("++(show (length (suite)))++" combinations)\n"++(showTimeDifference (diffClockTimes t2 t1))) ; putStrLn "Finished" } where summaryf = outputDir ++ "/summary.txt" resultDir = outputDir ++ "/results" clockMinRules :: [Rule] -> Int -> IO () clockMinRules [] _ = return () clockMinRules (h:t) n = do { t1 <- getClockTime ; suite <- getMinRuled h ; writeFile (resultDir ++ "/MinRule"++(show n)++".txt") (showSuite suite) ; t2 <- getClockTime ; appendFile summaryf ("\nMinRule "++(show n)++" ("++(show (length (suite)))++" combinations)\n"++(showTimeDifference (diffClockTimes t2 t1))) ; clockMinRules t (n+1) } clockFullRules :: [Rule] -> Int -> IO () clockFullRules [] _ = return () clockFullRules (h:t) n = do { t1 <- getClockTime ; suite <- getFullRuled h ; writeFile (resultDir ++ "/FullRule"++(show n)++".txt") (showSuite suite) ; t2 <- getClockTime ; appendFile summaryf ("\nFullRule "++(show n)++" ("++(show (length (suite)))++" combinations)\n"++(showTimeDifference (diffClockTimes t2 t1))) ; clockFullRules t (n+1) } getFullComb :: IO Suite getFullComb = return (fullComb inp) getMinComb :: IO Suite getMinComb = return (minimalComb inp) getMinRuled :: Rule -> IO Suite getMinRuled rule = return (minRuledComb rule inp) getFullRuled :: Rule -> IO Suite getFullRuled rule = return (fullRuledComb rule inp) showTimeDifference :: TimeDiff -> String showTimeDifference (TimeDiff _ _ _ _ _ sec ps) = if (ps<0) then showTimeAux (sec-1,1000+(div ps 1000000000)) else showTimeAux (sec,(div ps 1000000000)) showTimeAux :: (Int,Integer) -> String showTimeAux (sec,ps) = (show sec)++" seconds, "++(show ps)++" milisecs\n"