@@ -9,6 +9,7 @@ import Test.Tasty.Bench
99import Control.Monad.ST
1010import Data.Primitive
1111import Control.Monad.Trans.State.Strict
12+ import Data.Set (Set )
1213
1314-- These are fixed implementations of certain operations. In the event
1415-- that primitive changes its implementation of a function, these
@@ -25,6 +26,8 @@ import qualified ByteArray.Compare
2526import qualified PrimArray.Compare
2627import qualified PrimArray.Traverse
2728
29+ import qualified Data.Set as Set
30+
2831main :: IO ()
2932main = defaultMain
3033 [ bgroup " Array"
@@ -34,6 +37,9 @@ main = defaultMain
3437 , bench " unsafe" (nf (\ x -> runST (runStateT (Array.Traverse.Unsafe. traversePoly cheap x) 0 )) numbers)
3538 ]
3639 ]
40+ , bgroup " arrayFromListN"
41+ [ bench " set-to-list-to-array" (whnf arrayFromSet setOfIntegers1024)
42+ ]
3743 ]
3844 , bgroup " ByteArray"
3945 [ bgroup " compare"
@@ -62,6 +68,16 @@ main = defaultMain
6268 ]
6369 ]
6470
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+
6581cheap :: Int -> StateT Int (ST s ) Int
6682cheap i = modify (\ x -> x + i) >> return (i * i)
6783
0 commit comments