module Main where -- ghc -prof -auto-all --make -O2 ArrayCopyWithBounds.hs import Control.Monad( when ) import Data.Array.IO import Data.Int --import System.Random type Arr = IOUArray Int Int64 main = do -- rg <- getStdGen let size = 50000 nCopies = 10000 -- vs = map fromIntegral (randoms rg :: [Int]) a1 <- newTempArray size a2 <- newTempArray size doN nCopies (copyInto a1 a2 0 (size-1)) newTempArray :: Int -> IO Arr newTempArray len = newArray (0, len-1) 0 copyInto :: Arr -> Arr -> Int -> Int -> IO () copyInto c l beg end = blit beg where blit i = when (i <= end) (do ith <- readArray c i writeArray l i ith blit (i+1)) doN n act = go n where go i = when (i > 0) (act >> go (i-1))