Skip to content

Commit

Permalink
Benchmark arrayFromListN
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewthad committed Nov 18, 2024
1 parent b4f7965 commit d1db7ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit d1db7ab

Please sign in to comment.