@@ -9,6 +9,7 @@ import Test.Tasty.Bench
9
9
import Control.Monad.ST
10
10
import Data.Primitive
11
11
import Control.Monad.Trans.State.Strict
12
+ import Data.Set (Set )
12
13
13
14
-- These are fixed implementations of certain operations. In the event
14
15
-- that primitive changes its implementation of a function, these
@@ -25,6 +26,8 @@ import qualified ByteArray.Compare
25
26
import qualified PrimArray.Compare
26
27
import qualified PrimArray.Traverse
27
28
29
+ import qualified Data.Set as Set
30
+
28
31
main :: IO ()
29
32
main = defaultMain
30
33
[ bgroup " Array"
@@ -34,6 +37,9 @@ main = defaultMain
34
37
, bench " unsafe" (nf (\ x -> runST (runStateT (Array.Traverse.Unsafe. traversePoly cheap x) 0 )) numbers)
35
38
]
36
39
]
40
+ , bgroup " arrayFromListN"
41
+ [ bench " set-to-list-to-array" (whnf arrayFromSet setOfIntegers1024)
42
+ ]
37
43
]
38
44
, bgroup " ByteArray"
39
45
[ bgroup " compare"
@@ -62,6 +68,16 @@ main = defaultMain
62
68
]
63
69
]
64
70
71
+ setOfIntegers1024 :: Set Integer
72
+ {-# noinline setOfIntegers1024 #-}
73
+ setOfIntegers1024 = Set. fromList [1 .. 1024 ]
74
+
75
+ -- The performance of this is used to confirm whether or not arrayFromListN is
76
+ -- actining as a good consumer for list fusion.
77
+ arrayFromSet :: Set Integer -> Array Integer
78
+ {-# noinline arrayFromSet #-}
79
+ arrayFromSet s = arrayFromListN (Set. size s) (Set. toList s)
80
+
65
81
cheap :: Int -> StateT Int (ST s ) Int
66
82
cheap i = modify (\ x -> x + i) >> return (i * i)
67
83
0 commit comments