Skip to content

Commit 2f85481

Browse files
committed
Space tests for present and drawColor
Case Allocated GCs pollEvent + present 1 2,072 0 pollEvent + present 10 2,704 0 pollEvent + present 100 2,872 0 pollEvent + present 1000 2,872 0 Case Allocated GCs pollEvent + drawColor 1 2,160 0 pollEvent + drawColor 10 2,792 0 pollEvent + drawColor 100 2,960 0 pollEvent + drawColor 1000 2,960 0 pollEvent + drawColor 5000 2,960 0
1 parent b6388b2 commit 2f85481

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

bench/Space.hs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)