summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T5113.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/perf/should_run/T5113.hs')
-rw-r--r--testsuite/tests/perf/should_run/T5113.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/T5113.hs b/testsuite/tests/perf/should_run/T5113.hs
new file mode 100644
index 0000000000..e87bcb6cad
--- /dev/null
+++ b/testsuite/tests/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