@@ -39,6 +39,34 @@ main =
3939 " Allocated >3KB! Allocations should be constant."
4040 else Nothing )
4141 | i <- [1 , 10 , 100 , 1000 , 10000 ]
42+ ]
43+ sequence_
44+ [ validateAction
45+ (" pollEvent + present " ++ show i)
46+ pollEventPresentTest
47+ i
48+ (\ weight ->
49+ if weightGCs weight > 0
50+ then Just " Non-zero number of garbage collections!"
51+ else if weightAllocatedBytes weight > 3000
52+ then Just
53+ " Allocated >3KB! Allocations should be constant."
54+ else Nothing )
55+ | i <- [1 , 10 , 100 , 1000 ]
56+ ]
57+ sequence_
58+ [ validateAction
59+ (" pollEvent + drawColor " ++ show i)
60+ pollEventDrawColorTest
61+ i
62+ (\ weight ->
63+ if weightGCs weight > 0
64+ then Just " Non-zero number of garbage collections!"
65+ else if weightAllocatedBytes weight > 3000
66+ then Just
67+ " Allocated >3KB! Allocations should be constant."
68+ else Nothing )
69+ | i <- [1 , 10 , 100 , 1000 , 2000 ]
4270 ])
4371
4472-- | Test that merely polling does not allocate or engage the GC.
@@ -67,3 +95,36 @@ pollEventClearTest iters = do
6795 clear renderer
6896 go (i - 1 )
6997 go iters
98+
99+ -- | Test that merely polling and presenting does not allocate or
100+ -- engage the GC.
101+ pollEventPresentTest :: Int -> IO ()
102+ pollEventPresentTest iters = do
103+ initializeAll
104+ window <- createWindow " pollEventClearTest" defaultWindow
105+ renderer <- createRenderer window (- 1 ) defaultRenderer
106+ let go :: Int -> IO ()
107+ go 0 = pure ()
108+ go i = do
109+ _ <- pollEvent
110+ clear renderer
111+ present renderer
112+ go (i - 1 )
113+ go iters
114+
115+ -- | Test that merely polling and drawColoring does not allocate or
116+ -- engage the GC.
117+ pollEventDrawColorTest :: Int -> IO ()
118+ pollEventDrawColorTest iters = do
119+ initializeAll
120+ window <- createWindow " pollEventClearTest" defaultWindow
121+ renderer <- createRenderer window (- 1 ) defaultRenderer
122+ let go :: Int -> IO ()
123+ go 0 = pure ()
124+ go i = do
125+ _ <- pollEvent
126+ rendererDrawColor renderer $= V4 0 0 255 255
127+ clear renderer
128+ present renderer
129+ go (i - 1 )
130+ go iters
0 commit comments