on ae06339 help sign in
vty/test/BenchRenderChar.hs
32 lines 1.2 kB history raw
1{- benchmarks composing images using the renderChar operation.
2 - This is what Yi uses in Yi.UI.Vty.drawText. Ideally a sequence of renderChar images horizontally
3 - composed should provide no worse performance than a fill render op.
4 -}
5import Graphics.Vty
7import Control.Monad ( forM_ )
9import System.Time
11main = do
12 vty <- mkVty
13 (w, h) <- getSize vty
14 let test_chars = take 500 $ cycle $ [ c | c <- ['a'..'z']]
15 start_time_0 <- getClockTime
16 forM_ test_chars $ \test_char -> do
17 let test_image = test_image_using_renderChar test_char w h
18 out_pic = pic { pImage = test_image }
19 update vty out_pic
20 end_time_0 <- getClockTime
21 let start_time_1 = end_time_0
22 forM_ test_chars $ \test_char -> do
23 let test_image = renderFill attr test_char w h
24 out_pic = pic { pImage = test_image }
25 update vty out_pic
26 end_time_1 <- getClockTime
27 shutdown vty
28 putStrLn $ timeDiffToString $ diffClockTimes end_time_0 start_time_0
29 putStrLn $ timeDiffToString $ diffClockTimes end_time_1 start_time_1
31test_image_using_renderChar c w h = vertcat $ replicate h $ horzcat $ map (renderChar attr) (replicate w c)