Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bench/main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Test.Tasty.Bench
import Control.Monad.ST
import Data.Primitive
import Control.Monad.Trans.State.Strict
import Data.Set (Set)

-- These are fixed implementations of certain operations. In the event
-- that primitive changes its implementation of a function, these
Expand All @@ -25,6 +26,8 @@ import qualified ByteArray.Compare
import qualified PrimArray.Compare
import qualified PrimArray.Traverse

import qualified Data.Set as Set

main :: IO ()
main = defaultMain
[ bgroup "Array"
Expand All @@ -34,6 +37,9 @@ main = defaultMain
, bench "unsafe" (nf (\x -> runST (runStateT (Array.Traverse.Unsafe.traversePoly cheap x) 0)) numbers)
]
]
, bgroup "arrayFromListN"
[ bench "set-to-list-to-array" (whnf arrayFromSet setOfIntegers1024)
]
]
, bgroup "ByteArray"
[ bgroup "compare"
Expand Down Expand Up @@ -62,6 +68,16 @@ main = defaultMain
]
]

setOfIntegers1024 :: Set Integer
{-# noinline setOfIntegers1024 #-}
setOfIntegers1024 = Set.fromList [1..1024]

-- The performance of this is used to confirm whether or not arrayFromListN is
-- actining as a good consumer for list fusion.
arrayFromSet :: Set Integer -> Array Integer
{-# noinline arrayFromSet #-}
arrayFromSet s = arrayFromListN (Set.size s) (Set.toList s)

cheap :: Int -> StateT Int (ST s) Int
cheap i = modify (\x -> x + i) >> return (i * i)

Expand Down
1 change: 1 addition & 0 deletions primitive.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ benchmark bench
PrimArray.Traverse
build-depends:
base
, containers
, primitive
, deepseq
, tasty-bench
Expand Down
Loading