Skip to content

Commit 689db62

Browse files
committed
Benchmark arrayFromListN
1 parent b4f7965 commit 689db62

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

bench/main.hs

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Test.Tasty.Bench
99
import Control.Monad.ST
1010
import Data.Primitive
1111
import 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
2526
import qualified PrimArray.Compare
2627
import qualified PrimArray.Traverse
2728

29+
import qualified Data.Set as Set
30+
2831
main :: IO ()
2932
main = 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+
6581
cheap :: Int -> StateT Int (ST s) Int
6682
cheap i = modify (\x -> x + i) >> return (i * i)
6783

primitive.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ benchmark bench
115115
PrimArray.Traverse
116116
build-depends:
117117
base
118+
, containers
118119
, primitive
119120
, deepseq
120121
, tasty-bench

0 commit comments

Comments
 (0)