1{-# OPTIONS_GHC -Wno-deprecations #-}
3-------------------------------------------------------------------------------
4-- Investigate specific benchmarks more closely in isolation, possibly looking
5-- at GHC generated code for optimizing specific problematic cases.
6-------------------------------------------------------------------------------
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
12import Streamly.Internal.Data.Stream (Stream)
13import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
15import qualified Streamly.Data.Array as A
16import qualified Streamly.Internal.FileSystem.Handle as IFH
17import qualified Streamly.Data.Fold as FL
18import qualified Streamly.Internal.Data.Stream as S
19import qualified Streamly.Internal.Data.Stream.IsStream as Internal
27drain :: Monad m => S.Stream m a -> m ()
28drain = S.fold FL.drain
30{-# INLINE sourceUnfoldrM #-}
31sourceUnfoldrM :: Monad m => Stream m Int
32sourceUnfoldrM = S.unfoldrM step 0
37 else return (Just (cnt, cnt + 1))
39{-# INLINE sourceUnfoldrMN #-}
40sourceUnfoldrMN :: Monad m => Int -> Stream m Int
41sourceUnfoldrMN n = S.unfoldrM step n
46 else return (Just (cnt, cnt + 1))
48{-# INLINE sourceUnfoldr #-}
49sourceUnfoldr :: Monad m => Int -> Stream m Int
50sourceUnfoldr n = S.unfoldr step n
55 else Just (cnt, cnt + 1)
57-------------------------------------------------------------------------------
58-- take-drop composition
59-------------------------------------------------------------------------------
61takeAllDropOne :: Monad m => Stream m Int -> Stream m Int
62takeAllDropOne = S.drop 1 . S.take maxValue
64-- Requires -fspec-constr-recursive=5 for better fused code
65-- The number depends on how many times we compose it
67{-# INLINE takeDrop #-}
68takeDrop :: Monad m => Stream m Int -> m ()
70 takeAllDropOne . takeAllDropOne . takeAllDropOne . takeAllDropOne
72-------------------------------------------------------------------------------
73-- dropWhileFalse composition
74-------------------------------------------------------------------------------
76dropWhileFalse :: Monad m => Stream m Int -> Stream m Int
77dropWhileFalse = S.dropWhile (> maxValue)
79-- Requires -fspec-constr-recursive=5 for better fused code
80-- The number depends on how many times we compose it
82{-# INLINE dropWhileFalseX4 #-}
83dropWhileFalseX4 :: Monad m => Stream m Int -> m ()
84dropWhileFalseX4 = drain
85 . dropWhileFalse . dropWhileFalse . dropWhileFalse . dropWhileFalse
87-------------------------------------------------------------------------------
89-------------------------------------------------------------------------------
91{-# INLINE iterateSource #-}
94 => (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
95iterateSource g i n = f i (sourceUnfoldrMN n)
98 f x m = g (f (x - 1) m)
100-- Keep only the benchmark that is to be investiagted and comment out the rest.
101-- We keep all of them enabled by default for testing the build.
104 defaultMain [bench "unfoldr" $ nfIO $
105 randomRIO (1,1) >>= \n -> drain (sourceUnfoldr n)]
106 defaultMain [bench "take-drop" $ nfIO $ takeDrop sourceUnfoldrM]
107 defaultMain [bench "dropWhileFalseX4" $
108 nfIO $ dropWhileFalseX4 sourceUnfoldrM]
109 defaultMain [bench "iterate-mapM" $
110 nfIO $ drain $ iterateSource (S.mapM return) 100000 10]
112 inText <- openFile "benchmark/text-processing/gutenberg-500.txt" ReadMode
113 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
117 $ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
126 mkBenchText name h action =
127 env (hSeek h AbsoluteSeek 0) (\_ -> bench name $ nfIO action)
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