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.Mut as MArray
29import Gauge hiding (env)
30import Streamly.Benchmark.Common
32-------------------------------------------------------------------------------
34-------------------------------------------------------------------------------
36{-# INLINE sourceUnfoldrM #-}
37sourceUnfoldrM :: (IsStream t, MonadAsync m) => Int -> Int -> t m Int
38sourceUnfoldrM value n = Stream.unfoldrM step n
43 else return (Just (cnt, cnt + 1))
48 => String -> (Int -> a) -> (a -> IO b) -> Benchmark
49benchIO name src sink =
50 bench name $ nfIO $ randomRIO (1,1) >>= sink . src
52o_n_space_serial_marray :: Int -> MArray.Array Int -> [Benchmark]
53o_n_space_serial_marray value array =
54 [ benchIO "partitionBy (< 0)" (const array)
55 $ MArray.partitionBy (< 0)
56 , benchIO "partitionBy (> 0)" (const array)
57 $ MArray.partitionBy (> 0)
58 , benchIO "partitionBy (< value/2)" (const array)
59 $ MArray.partitionBy (< (value `div` 2))
60 , benchIO "partitionBy (> value/2)" (const array)
61 $ MArray.partitionBy (> (value `div` 2))
64-------------------------------------------------------------------------------
66-------------------------------------------------------------------------------
69moduleName = "Data.Array.Foreign.Mut"
73 runWithCLIOptsEnv defaultStreamSize alloc allBenchmarks
77 alloc value = MArray.fromStream (sourceUnfoldrM value 0 :: SerialT IO Int)
79 allBenchmarks array value =
80 [ bgroup (o_1_space_prefix moduleName) $
81 o_n_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