ef65db3a56cd0c600e7f138d78cc1dd99e198ceb
[ghc.git] / testsuite / tests / perf / should_run / T7257.hs
1 {-# LANGUAGE BangPatterns #-}
2 module Main where
3
4 import qualified Data.ByteString as S
5 import Data.IORef
6 import Control.Monad
7
8 makeBs :: Int -> S.ByteString
9 makeBs n = S.replicate n (fromIntegral n)
10
11 doStuff :: IORef [S.ByteString] -> Int -> IO ()
12 doStuff ref n = do
13 let !bs = makeBs n
14 modifyIORef ref (bs:)
15 {-# NOINLINE doStuff #-}
16
17 undo :: IORef [S.ByteString] -> IO ()
18 undo ref = do
19 h <- atomicModifyIORef ref (\(x:xs) -> (xs,x))
20 S.length h `seq` return ()
21
22 main = do
23 ref <- newIORef [S.empty]
24 let fn n = do
25 doStuff ref n
26 when (rem 5 n /= 0 ) $ undo ref
27
28 mapM_ fn (take 5000000 $ cycle [1..100])
29 var <- readIORef ref
30 print $ length var