2-- Module : Streamly.Benchmark.Data.Array.Foreign.Mut
3-- Copyright : (c) 2021 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
11#ifdef __HADDOCK_VERSION__
16{-# LANGUAGE TemplateHaskell #-}
17{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
20module Main (main) where
22import Control.DeepSeq (NFData(..))
23import Streamly.Prelude (MonadAsync, SerialT, IsStream)
24import System.Random (randomRIO)
26import qualified Streamly.Prelude as Stream
27import qualified Streamly.Internal.Data.Array.Foreign as Array
28import qualified Streamly.Internal.Data.Array.Foreign.Mut as MArray
30import Gauge hiding (env)
31import Streamly.Benchmark.Common
33-------------------------------------------------------------------------------
35-------------------------------------------------------------------------------
37{-# INLINE sourceUnfoldrM #-}
38sourceUnfoldrM :: (IsStream t, MonadAsync m) => Int -> Int -> t m Int
39sourceUnfoldrM value n = Stream.unfoldrM step n
44 else return (Just (cnt, cnt + 1))
49 => String -> (Int -> a) -> (a -> IO b) -> Benchmark
50benchIO name src sink =
51 bench name $ nfIO $ randomRIO (1,1) >>= sink . src
53o_1_space_serial_marray ::
54 Int -> (MArray.Array Int, Array.Array Int) -> [Benchmark]
55o_1_space_serial_marray value ~(array, indices) =
56 [ benchIO "partitionBy (< 0)" (const array)
57 $ MArray.partitionBy (< 0)
58 , benchIO "partitionBy (> 0)" (const array)
59 $ MArray.partitionBy (> 0)
60 , benchIO "partitionBy (< value/2)" (const array)
61 $ MArray.partitionBy (< (value `div` 2))
62 , benchIO "partitionBy (> value/2)" (const array)
63 $ MArray.partitionBy (> (value `div` 2))
64 , benchIO "strip (< value/2 || > value/2)" (const array)
65 $ MArray.strip (\x -> x < value `div` 2 || x > value `div` 2)
66 , benchIO "strip (> 0)" (const array)
68 , benchIO "modifyIndices (+ 1)" (const indices)
69 $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
70 . Stream.unfold Array.read
73-------------------------------------------------------------------------------
75-------------------------------------------------------------------------------
78moduleName = "Data.Array.Foreign.Mut"
82 runWithCLIOptsEnv defaultStreamSize alloc allBenchmarks
87 marr <- MArray.fromStream (sourceUnfoldrM value 0 :: SerialT IO Int)
88 indices <- Array.fromStream (sourceUnfoldrM value 0 :: SerialT IO Int)
89 return (marr, indices)
91 allBenchmarks array value =
92 [ bgroup (o_1_space_prefix moduleName) $
93 o_1_space_serial_marray value array
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list