Add a perf test for #7257
authorSimon Marlow <marlowsd@gmail.com>
Fri, 21 Sep 2012 13:31:01 +0000 (14:31 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Mon, 24 Sep 2012 08:22:53 +0000 (09:22 +0100)
testsuite/tests/perf/should_run/T7257.hs [new file with mode: 0644]
testsuite/tests/perf/should_run/T7257.stdout [new file with mode: 0644]
testsuite/tests/perf/should_run/all.T

diff --git a/testsuite/tests/perf/should_run/T7257.hs b/testsuite/tests/perf/should_run/T7257.hs
new file mode 100644 (file)
index 0000000..ef65db3
--- /dev/null
@@ -0,0 +1,30 @@
+{-# LANGUAGE BangPatterns #-}
+module Main where
+
+import qualified Data.ByteString as S
+import Data.IORef
+import Control.Monad
+
+makeBs :: Int -> S.ByteString
+makeBs n = S.replicate n (fromIntegral n)
+
+doStuff :: IORef [S.ByteString] -> Int -> IO ()
+doStuff ref n = do
+    let !bs = makeBs n
+    modifyIORef ref (bs:)
+{-# NOINLINE doStuff #-}
+
+undo :: IORef [S.ByteString] -> IO ()
+undo ref = do
+    h <- atomicModifyIORef ref (\(x:xs) -> (xs,x))
+    S.length h `seq` return ()
+
+main = do
+    ref <- newIORef [S.empty]
+    let fn n = do
+        doStuff ref n
+        when (rem 5 n /= 0 ) $ undo ref
+        
+    mapM_ fn (take 5000000 $ cycle [1..100])
+    var <- readIORef ref
+    print $ length var
diff --git a/testsuite/tests/perf/should_run/T7257.stdout b/testsuite/tests/perf/should_run/T7257.stdout
new file mode 100644 (file)
index 0000000..e69de29
index c7582d6..22acf28 100644 (file)
@@ -237,3 +237,20 @@ test('T5536',
     compile_and_run,
     ['-O'])
 
+test('T7257',
+     [if_wordsize(32,
+          stats_range_field('bytes allocated', 1150000000, 10)),
+                           # expected value: 1246287228 (i386/Linux)
+      if_wordsize(32,
+          stats_range_field('peak_megabytes_allocated', 150, 5)),
+                           # unkonwn
+      if_wordsize(64,
+          stats_range_field('bytes allocated', 1774893760, 5)),
+                           # 2012-09-21: 1774893760 (amd64/Linux)
+      if_wordsize(64,
+          stats_range_field('peak_megabytes_allocated', 227, 5)),
+                           # 2012-09-21: 227 (amd64/Linux)
+
+      only_ways(['normal'])
+     ],
+    compile_and_run, ['-O'])