on efecb26 help sign in
114 lines 3.3 kB history raw
1-- |
2-- Module : Data.Stream
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
7{-# LANGUAGE CPP #-}
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
12#undef FUSION_CHECK
13#ifdef FUSION_CHECK
14{-# OPTIONS_GHC -ddump-simpl -ddump-to-file -dsuppress-all #-}
15#endif
17module Main (main) where
19import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
21import qualified Stream.Eliminate as Elimination
22#ifndef USE_STREAMLY_CORE
23import qualified Stream.Exceptions as Exceptions
24#endif
25import qualified Stream.Expand as NestedStream
26import qualified Stream.Generate as Generation
27import qualified Stream.Lift as Lift
28import qualified Stream.Reduce as NestedFold
29#ifdef USE_PRELUDE
30import qualified Stream.Split as Split
31#endif
32import qualified Stream.Transform as Transformation
34import Streamly.Benchmark.Common
36#ifdef FUSION_CHECK
37import Data.Function ((&))
38import Streamly.Data.Stream (Stream)
39import qualified Streamly.Internal.Data.Stream as Stream
40import qualified Streamly.Internal.Data.Fold as Fold
41import qualified Data.Foldable as Foldable
42import Stream.Common
43#endif
45moduleName :: String
46#ifdef USE_STREAMK
47moduleName = "Data.Stream.StreamDK"
48#else
49moduleName = "Data.Stream"
50#endif
52-------------------------------------------------------------------------------
53-- Main
54-------------------------------------------------------------------------------
56-- In addition to gauge options, the number of elements in the stream can be
57-- passed using the --stream-size option.
58--
59main :: IO ()
60main = do
61#ifndef FUSION_CHECK
62 env <- mkHandleBenchEnv
63 runWithCLIOpts defaultStreamSize (allBenchmarks env)
65 where
67 allBenchmarks env size = Prelude.concat
68 [ Generation.benchmarks moduleName size
69 , Elimination.benchmarks moduleName size
70#ifndef USE_STREAMLY_CORE
71 , Exceptions.benchmarks moduleName env size
72#endif
73#ifdef USE_PRELUDE
74 , Split.benchmarks moduleName env
75#endif
76 , Transformation.benchmarks moduleName size
77 , NestedFold.benchmarks moduleName size
78 , Lift.benchmarks moduleName size
79 , NestedStream.benchmarks moduleName size
80 ]
81#else
82 -- Enable FUSION_CHECK macro at the beginning of the file
83 -- Enable one benchmark below, and run the benchmark
84 -- Check the .dump-simpl output
85 let value = 100000
86 let input = sourceUnfoldrM value 1
88 -- Stream.foldr (:) [] input >>= print . Prelude.length
89 -- Stream.fold (Fold.foldr' (:) []) input >>= print . Prelude.length
91 -- Stream.toList input >>= print . Prelude.length
92 -- Stream.fold Fold.toList input >>= print . Prelude.length
94 -- We can automatically assert that these generate identical core
96 -- Stream.drain input >>= print
97 -- Stream.fold Fold.drain input >>= print
99 -- Stream.last input >>= print
100 -- Stream.fold Fold.latest input >>= print
102 -- Stream.length input >>= print
103 -- Stream.fold Fold.length input >>= print
105 -- Stream.maximum input >>= print
106 -- Stream.fold Fold.maximum input >>= print
108 -- Stream.head input >>= print
109 -- Stream.fold Fold.one input >>= print
111 -- composeN 4 (Stream.scanl' (+) 0) input
112 composeN 4 (Stream.scan (Fold.foldl' (+) 0)) input
113 return ()
114#endif