diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2011-04-21 14:35:14 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2011-04-21 14:35:14 +0100 |
commit | dad1bf2d46dc5b188aa6c710177645aee5f849a0 (patch) | |
tree | 145bce0a3befdecd466ebd6bbb00be924eff5cbf /testsuite | |
parent | 81525f9440e0734324d7b37bf2c6c723dcf698d3 (diff) | |
download | haskell-dad1bf2d46dc5b188aa6c710177645aee5f849a0.tar.gz |
Test Trac #5113
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/ghc-regress/perf/should_run/T5113.hs | 31 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/perf/should_run/T5113.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/perf/should_run/all.T | 8 |
3 files changed, 40 insertions, 0 deletions
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 index 0000000000..e87bcb6cad --- /dev/null +++ b/testsuite/tests/ghc-regress/perf/should_run/T5113.hs @@ -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 index 0000000000..0cfbf08886 --- /dev/null +++ b/testsuite/tests/ghc-regress/perf/should_run/T5113.stdout @@ -0,0 +1 @@ +2 diff --git a/testsuite/tests/ghc-regress/perf/should_run/all.T b/testsuite/tests/ghc-regress/perf/should_run/all.T index f1d918d892..23ec4523a4 100644 --- a/testsuite/tests/ghc-regress/perf/should_run/all.T +++ b/testsuite/tests/ghc-regress/perf/should_run/all.T @@ -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']) + |