blob: 69348320134c9a714885b5ade2783086a3560ccf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Main ( main ) where
import GHC.Exts
import GHC.Prim
import GHC.ST
main = putStr
(test_sizeofArray
++ "\n" ++ test_sizeofMutableArray
++ "\n"
)
test_sizeofArray :: String
test_sizeofArray = flip shows "\n" $ runST $ ST $ \ s# -> go 0 [] s#
where
go i@(I# i#) acc s#
| i < 1000 = case newArray# i# 0 s# of
(# s2#, marr# #) -> case unsafeFreezeArray# marr# s2# of
(# s3#, arr# #) -> case sizeofArray# arr# of
j# -> go (i+1) ((I# j#):acc) s3#
| otherwise = (# s#, reverse acc #)
test_sizeofMutableArray :: String
test_sizeofMutableArray = flip shows "\n" $ runST $ ST $ \ s# -> go 0 [] s#
where
go i@(I# i#) acc s#
| i < 1000 = case newArray# i# 0 s# of
(# s2#, marr# #) -> case sizeofMutableArray# marr# of
j# -> go (i+1) ((I# j#):acc) s2#
| otherwise = (# s#, reverse acc #)
|