module Benchmark where import CTy.DSL import CTy.TestVal -- import CTy.Concretization import CTy.CRule import CTy.TCgen import qualified ExampleCT1 import qualified ExampleCT2 import Time import List import System.Directory -- Benchmark testing main :: IO() main = do { benchmark "BM1" ExampleCT1.suites ; benchmark "BM2" ExampleCT2.suites ; benchmark "BM1 sorted" ExampleCT1.suitesSort ; benchmark "BM2 sorter" ExampleCT2.suitesSort ; } forceCalculation suite = do { t1 <- getClockTime ; putStr ("\n ** " ++ (show . sum . map length $ suite)) ; t2 <- getClockTime ; putStr (", #" ++ show (length suite)) ; putStr (", TIME = " ++ showTimeDifference (diffClockTimes t2 t1)) } benchmark name suites = do { putStr ("\n\n** Measuring " ++ name) ; sequence_ (map forceCalculation suites) ; putStr "\n** Done." } 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)++" sec, "++(show ps)++" msec"