on dc8be4e help sign in
vty/test/benchmark.hs
57 lines 1.8 kB history raw
1{-# LANGUAGE QuasiQuotes #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3module Main where
5import Graphics.Vty
7import qualified BenchImageFuzz
8import qualified BenchNoDiffOpt
9import qualified BenchRenderChar
10import qualified BenchVerticalScroll
12import Control.Monad
14import Data.Maybe
15import Data.List
17import System.Environment
18import System.Posix.Process
20import Verify
22main = do
23 args <- getArgs
24 let benches = [ ("no-diff-opt-0", BenchNoDiffOpt.bench_0)
25 , ("render-char-0", BenchRenderChar.bench_0)
26 , ("render-char-1", BenchRenderChar.bench_1)
27 , ("vertical-scroll-0", BenchVerticalScroll.bench_0)
28 , ("image-fuzz-0", BenchImageFuzz.bench_0) ]
29 help = forM_ benches $ \(b,_) -> putStrLn $ "--" ++ b
30 case args of
31 ["--help"] -> help
32 ["-h" ] -> help
33 _ -> do
34 let args' = if args /= []
35 then args
36 else map fst benches
37 -- drop the dash-dash "--"
38 results <- forM args' $ \(_ : _ : b_name) -> do
39 case lookup b_name benches of
40 Just b -> bench b_name b
41 Nothing -> fail $ "No benchmark named " ++ b_name
42 print results
43 return ()
45bench b_name b = do
46 putStrLn $ "starting " ++ b_name
47 Bench b_data_gen b_proc <- b
48 b_data <- b_data_gen
49 start_times <- b_data `deepseq` getProcessTimes
50 b_proc b_data
51 end_times <- getProcessTimes
52 let user_time = userTime end_times - userTime start_times
53 system_time = systemTime end_times - systemTime start_times
54 putStrLn $ "user time: " ++ show user_time
55 putStrLn $ "system time: " ++ show system_time
56 return (b_name, user_time, system_time)