Skip to content

Commit 2db31b2

Browse files
Split the Parser module into "main" and "benchmarks"
1 parent f844212 commit 2db31b2

File tree

4 files changed

+87
-51
lines changed

4 files changed

+87
-51
lines changed

benchmark/Streamly/Benchmark/Data/Parser.hs

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
{-# LANGUAGE ScopedTypeVariables #-}
1717
{-# OPTIONS_GHC -Wno-orphans #-}
1818

19-
module Main
19+
module Streamly.Benchmark.Data.Parser
2020
(
21-
main
21+
benchmarks
22+
, sourceUnfoldrM
2223
) where
2324

2425
import Control.Applicative ((<|>))
@@ -703,9 +704,6 @@ concatSequence =
703704
-- Benchmarks
704705
-------------------------------------------------------------------------------
705706

706-
moduleName :: String
707-
moduleName = "Data.Parser"
708-
709707
instance NFData ParseError where
710708
{-# INLINE rnf #-}
711709
rnf (ParseError x) = rnf x
@@ -823,46 +821,3 @@ benchmarks value env arrays =
823821
{-# NOINLINE parseManyGroupsRollingEitherAlt1 #-}
824822
parseManyGroupsRollingEitherAlt1 =
825823
parseManyGroupsRollingEitherAlt (>) value
826-
827-
-------------------------------------------------------------------------------
828-
-- Driver
829-
-------------------------------------------------------------------------------
830-
831-
main :: IO ()
832-
main = do
833-
#ifndef FUSION_CHECK
834-
env <- mkHandleBenchEnv
835-
runWithCLIOptsEnv defaultStreamSize alloc (allBenchmarks env)
836-
837-
where
838-
839-
alloc value = Stream.fold Fold.toList $ Array.chunksOf 100 $ sourceUnfoldrM value 0
840-
841-
allBenchmarks env arrays value =
842-
let allBenches = benchmarks value env arrays
843-
get x = map snd $ filter ((==) x . fst) allBenches
844-
o_1_space = get SpaceO_1
845-
o_n_heap = get HeapO_n
846-
o_n_space = get SpaceO_n
847-
in
848-
[ bgroup (o_1_space_prefix moduleName) o_1_space
849-
, bgroup (o_n_heap_prefix moduleName) o_n_heap
850-
, bgroup (o_n_space_prefix moduleName) o_n_space
851-
]
852-
#else
853-
-- Enable FUSION_CHECK macro at the beginning of the file
854-
-- Enable one benchmark below, and run the benchmark
855-
-- Check the .dump-simpl output
856-
let value = 100000
857-
-- let input = sourceUnfoldrM value 1
858-
-- manyTill value input
859-
-- deintercalate value input
860-
-- deintercalate1 value input
861-
-- deintercalateAll value input
862-
-- sepByWords input
863-
-- sepByAllWords input
864-
-- sepBy1 input
865-
-- sepByWords1 input
866-
takeFramedByEsc_ value (sourceEscapedFrames value 1)
867-
return ()
868-
#endif
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#undef FUSION_CHECK
2+
#ifdef FUSION_CHECK
3+
{-# OPTIONS_GHC -ddump-simpl -ddump-to-file -dsuppress-all #-}
4+
#endif
5+
6+
-- |
7+
-- Module : Streamly.Benchmark.Data.Parser
8+
-- Copyright : (c) 2020 Composewell Technologies
9+
--
10+
-- License : BSD-3-Clause
11+
-- Maintainer : [email protected]
12+
13+
{-# LANGUAGE CPP #-}
14+
{-# LANGUAGE FlexibleContexts #-}
15+
{-# LANGUAGE ScopedTypeVariables #-}
16+
{-# OPTIONS_GHC -Wno-orphans #-}
17+
18+
module Main
19+
(
20+
main
21+
) where
22+
23+
import Prelude hiding
24+
(any, all, take, sequence, sequence_, sequenceA, takeWhile, dropWhile, span)
25+
26+
import qualified Streamly.Internal.Data.Array as Array
27+
import qualified Streamly.Internal.Data.Fold as Fold
28+
import qualified Streamly.Data.Stream as Stream
29+
30+
import Test.Tasty.Bench hiding (env)
31+
import Streamly.Benchmark.Common
32+
import Streamly.Benchmark.Common.Handle
33+
import Streamly.Benchmark.Data.Parser
34+
35+
moduleName :: String
36+
moduleName = "Data.Parser"
37+
38+
-------------------------------------------------------------------------------
39+
-- Driver
40+
-------------------------------------------------------------------------------
41+
42+
main :: IO ()
43+
main = do
44+
#ifndef FUSION_CHECK
45+
env <- mkHandleBenchEnv
46+
runWithCLIOptsEnv defaultStreamSize alloc (allBenchmarks env)
47+
48+
where
49+
50+
alloc value = Stream.fold Fold.toList $ Array.chunksOf 100 $ sourceUnfoldrM value 0
51+
52+
allBenchmarks env arrays value =
53+
let allBenches = benchmarks value env arrays
54+
get x = map snd $ filter ((==) x . fst) allBenches
55+
o_1_space = get SpaceO_1
56+
o_n_heap = get HeapO_n
57+
o_n_space = get SpaceO_n
58+
in
59+
[ bgroup (o_1_space_prefix moduleName) o_1_space
60+
, bgroup (o_n_heap_prefix moduleName) o_n_heap
61+
, bgroup (o_n_space_prefix moduleName) o_n_space
62+
]
63+
#else
64+
-- Enable FUSION_CHECK macro at the beginning of the file
65+
-- Enable one benchmark below, and run the benchmark
66+
-- Check the .dump-simpl output
67+
let value = 100000
68+
-- let input = sourceUnfoldrM value 1
69+
-- manyTill value input
70+
-- deintercalate value input
71+
-- deintercalate1 value input
72+
-- deintercalateAll value input
73+
-- sepByWords input
74+
-- sepByAllWords input
75+
-- sepBy1 input
76+
-- sepByWords1 input
77+
takeFramedByEsc_ value (sourceEscapedFrames value 1)
78+
return ()
79+
#endif

benchmark/streamly-benchmarks.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,10 @@ benchmark Data.MutArray
329329
benchmark Data.Parser
330330
import: bench-options
331331
type: exitcode-stdio-1.0
332-
hs-source-dirs: Streamly/Benchmark/Data
333-
main-is: Parser.hs
332+
hs-source-dirs: .
333+
main-is: Streamly/Benchmark/Data/ParserMain.hs
334+
other-modules:
335+
Streamly.Benchmark.Data.Parser
334336
if impl(ghcjs)
335337
buildable: False
336338
else

hie.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cradle:
3232
component: "bench:Data.Fold.Window"
3333
- path: "./benchmark/Streamly/Benchmark/Data/MutArray.hs"
3434
component: "bench:Data.MutArray"
35-
- path: "./benchmark/Streamly/Benchmark/Data/Parser.hs"
35+
- path: "./benchmark/Streamly/Benchmark/Data/"
3636
component: "bench:Data.Parser"
3737
- path: "./benchmark/Streamly/Benchmark/Data/ParserK.hs"
3838
component: "bench:Data.ParserK"

0 commit comments

Comments
 (0)