2-- Module : NestedUnfoldOps
3-- Copyright : (c) 2019 Composewell Technologies
6-- Maintainer : streamly@composewell.com
8module Streamly.Benchmark.Data.NestedUnfoldOps where
10import Control.Monad.IO.Class (MonadIO (..))
11import Streamly.Internal.Data.Unfold (Unfold)
13import qualified Streamly.Internal.Data.Unfold as UF
14import qualified Streamly.Internal.Data.Fold as FL
16-- n * (n + 1) / 2 == linearCount
17concatCount :: Int -> Int
18concatCount linearCount =
19 round (((1 + 8 * fromIntegral linearCount)**(1/2::Double) - 1) / 2)
22nestedCount2 :: Int -> Int
23nestedCount2 linearCount = round (fromIntegral linearCount**(1/2::Double))
26nestedCount3 :: Int -> Int
27nestedCount3 linearCount = round (fromIntegral linearCount**(1/3::Double))
29-------------------------------------------------------------------------------
30-- Stream generation and elimination
31-------------------------------------------------------------------------------
33-- generate numbers up to the argument value
35source :: Monad m => Int -> Unfold m Int Int
36source n = UF.enumerateFromToIntegral n
38-------------------------------------------------------------------------------
40-------------------------------------------------------------------------------
43toNull :: MonadIO m => Int -> Int -> m ()
44toNull linearCount start = do
45 let end = start + nestedCount2 linearCount
47 (UF.map (\(x, y) -> x + y)
48 $ UF.outerProduct (source end) (source end))
49 FL.drain (start, start)
52toNull3 :: MonadIO m => Int -> Int -> m ()
53toNull3 linearCount start = do
54 let end = start + nestedCount3 linearCount
56 (UF.map (\(x, y) -> x + y)
57 $ UF.outerProduct (source end)
58 ((UF.map (\(x, y) -> x + y)
59 $ UF.outerProduct (source end) (source end))))
60 FL.drain (start, (start, start))
63concat :: MonadIO m => Int -> Int -> m ()
64concat linearCount start = do
65 let end = start + concatCount linearCount
67 (UF.concat (source end) (source end))
71toList :: MonadIO m => Int -> Int -> m [Int]
72toList linearCount start = do
73 let end = start + nestedCount2 linearCount
75 (UF.map (\(x, y) -> x + y)
76 $ UF.outerProduct (source end) (source end))
77 FL.toList (start, start)
79{-# INLINE toListSome #-}
80toListSome :: MonadIO m => Int -> Int -> m [Int]
81toListSome linearCount start = do
82 let end = start + nestedCount2 linearCount
84 (UF.take 1000 $ (UF.map (\(x, y) -> x + y)
85 $ UF.outerProduct (source end) (source end)))
86 FL.toList (start, start)
88{-# INLINE filterAllOut #-}
89filterAllOut :: MonadIO m => Int -> Int -> m ()
90filterAllOut linearCount start = do
91 let end = start + nestedCount2 linearCount
94 $ UF.map (\(x, y) -> x + y)
95 $ UF.outerProduct (source end) (source end))
96 FL.drain (start, start)
98{-# INLINE filterAllIn #-}
99filterAllIn :: MonadIO m => Int -> Int -> m ()
100filterAllIn linearCount start = do
101 let end = start + nestedCount2 linearCount
104 $ UF.map (\(x, y) -> x + y)
105 $ UF.outerProduct (source end) (source end))
106 FL.drain (start, start)
108{-# INLINE filterSome #-}
109filterSome :: MonadIO m => Int -> Int -> m ()
110filterSome linearCount start = do
111 let end = start + nestedCount2 linearCount
113 (UF.filter (> 1100000)
114 $ UF.map (\(x, y) -> x + y)
115 $ UF.outerProduct (source end) (source end))
116 FL.drain (start, start)
118{-# INLINE breakAfterSome #-}
119breakAfterSome :: MonadIO m => Int -> Int -> m ()
120breakAfterSome linearCount start = do
121 let end = start + nestedCount2 linearCount
123 (UF.takeWhile (<= 1100000)
124 $ UF.map (\(x, y) -> x + y)
125 $ UF.outerProduct (source end) (source end))
126 FL.drain (start, start)
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