Test Trac #5113
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Apr 2011 13:35:14 +0000 (14:35 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Apr 2011 13:35:14 +0000 (14:35 +0100)
testsuite/tests/ghc-regress/perf/should_run/T5113.hs [new file with mode: 0644]
testsuite/tests/ghc-regress/perf/should_run/T5113.stdout [new file with mode: 0644]
testsuite/tests/ghc-regress/perf/should_run/all.T

diff --git a/testsuite/tests/ghc-regress/perf/should_run/T5113.hs b/testsuite/tests/ghc-regress/perf/should_run/T5113.hs
new file mode 100644 (file)
index 0000000..e87bcb6
--- /dev/null
@@ -0,0 +1,31 @@
+{-# LANGUAGE BangPatterns #-}
+module Main where
+
+import Data.Array.Base (unsafeRead, unsafeWrite)
+import Data.Array.ST
+import Data.Array.Unboxed
+import Control.Monad.ST
+
+main = print (divisorCounts 1000000 ! 342)
+
+isqrt :: Int -> Int
+isqrt n = floor (sqrt $ fromIntegral n)
+
+divisorCounts :: Int -> UArray Int Int
+divisorCounts n = runSTUArray $ do
+    let !rt = isqrt n
+    darr <- newArray (0,n) 1 :: ST s (STUArray s Int Int)
+    let inc i = unsafeRead darr i >>= \k -> unsafeWrite darr i (k+1)
+        note step i
+            | i > n     = return ()
+            | otherwise = do
+                inc i
+                note step (i+step)
+        count j
+            | j > rt    = return ()
+            | otherwise = do
+                note (2*j) (j*j)
+                count (j+2)
+    note 2 4
+    count 3
+    return darr
diff --git a/testsuite/tests/ghc-regress/perf/should_run/T5113.stdout b/testsuite/tests/ghc-regress/perf/should_run/T5113.stdout
new file mode 100644 (file)
index 0000000..0cfbf08
--- /dev/null
@@ -0,0 +1 @@
+2
index f1d918d..23ec452 100644 (file)
@@ -107,3 +107,11 @@ test('T149',
      run_command,
      ['$MAKE -s --no-print-directory T149'])
 
+test('T5113',
+     [stats_num_field('bytes allocated', 8000000,
+                                         9000000),
+      only_ways(['normal'])
+      ],
+     compile_and_run,
+     ['-O'])
+