on master help sign in
Move splitting benchmarks from FileSystem.Handle to Prelude.Serial
7f1b5d2Anurag Hooda
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+2−167
@@ -383,177 +383,12 @@ o_1_space_reduce_read_grouped env =
383 ]
383 ]
384 ]
384 ]
385
385
386−-------------------------------------------------------------------------------
387−-- reduce with splitting transformations
388−-------------------------------------------------------------------------------
389−
390−lf :: Word8
391−lf = fromIntegral (ord '\n')
392−
393−toarr :: String -> A.Array Word8
394−toarr = A.fromList . map (fromIntegral . ord)
395−
396−-- | Split on line feed.
397−splitOn :: Handle -> IO Int
398−splitOn inh =
399− (S.length $ S.splitOn (== lf) FL.drain
400− $ S.unfold FH.read inh) -- >>= print
401−
402−#ifdef INSPECTION
403−inspect $ hasNoTypeClasses 'splitOn
404−inspect $ 'splitOn `hasNoType` ''Step
405−inspect $ 'splitOn `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
406−inspect $ 'splitOn `hasNoType` ''A.ReadUState -- FH.read/A.read
407−#endif
408−
409−-- | Split suffix on line feed.
410−splitOnSuffix :: Handle -> IO Int
411−splitOnSuffix inh =
412− (S.length $ S.splitOnSuffix (== lf) FL.drain
413− $ S.unfold FH.read inh) -- >>= print
414−
415−#ifdef INSPECTION
416−inspect $ hasNoTypeClasses 'splitOnSuffix
417−inspect $ 'splitOnSuffix `hasNoType` ''Step
418−inspect $ 'splitOnSuffix `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
419−inspect $ 'splitOnSuffix `hasNoType` ''A.ReadUState -- FH.read/A.read
420−#endif
421−
422−-- | Split suffix with line feed.
423−splitWithSuffix :: Handle -> IO Int
424−splitWithSuffix inh =
425− (S.length $ S.splitWithSuffix (== lf) FL.drain
426− $ S.unfold FH.read inh) -- >>= print
427−
428−#ifdef INSPECTION
429−inspect $ hasNoTypeClasses 'splitWithSuffix
430−inspect $ 'splitWithSuffix `hasNoType` ''Step
431−inspect $ 'splitWithSuffix `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
432−inspect $ 'splitWithSuffix `hasNoType` ''A.ReadUState -- FH.read/A.read
433−#endif
434−
435−-- | Split on line feed.
436−parseManySepBy :: Handle -> IO Int
437−parseManySepBy inh =
438− (S.length $ IP.parseMany (PR.sliceSepBy (== lf) FL.drain)
439− (S.unfold FH.read inh)) -- >>= print
440−
441−-- | Words by space
442−wordsBy :: Handle -> IO Int
443−wordsBy inh =
444− (S.length $ S.wordsBy isSp FL.drain
445− $ S.unfold FH.read inh) -- >>= print
446−
447−#ifdef INSPECTION
448−inspect $ hasNoTypeClasses 'wordsBy
449−inspect $ 'wordsBy `hasNoType` ''Step
450−inspect $ 'wordsBy `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
451−inspect $ 'wordsBy `hasNoType` ''A.ReadUState -- FH.read/A.read
452−#endif
453−
454−-- | Split on a word8 sequence.
455−splitOnSeq :: String -> Handle -> IO Int
456−splitOnSeq str inh =
457− (S.length $ IP.splitOnSeq (toarr str) FL.drain
458− $ S.unfold FH.read inh) -- >>= print
459−
460−#ifdef INSPECTION
461−-- inspect $ hasNoTypeClasses 'splitOnSeq
462−-- inspect $ 'splitOnSeq `hasNoType` ''Step
463−#endif
464−
465−-- | Split on a word8 sequence.
466−splitOnSeq100k :: Handle -> IO Int
467−splitOnSeq100k inh = do
468− arr <- A.fromStream $ S.replicate 100000 123
469− (S.length $ IP.splitOnSeq arr FL.drain
470− $ S.unfold FH.read inh) -- >>= print
471−
472−-- | Split on suffix sequence.
473−splitOnSuffixSeq :: String -> Handle -> IO Int
474−splitOnSuffixSeq str inh =
475− (S.length $ IP.splitOnSuffixSeq (toarr str) FL.drain
476− $ S.unfold FH.read inh) -- >>= print
477−
478−#ifdef INSPECTION
479−-- inspect $ hasNoTypeClasses 'splitOnSuffixSeq
480−-- inspect $ 'splitOnSuffixSeq `hasNoType` ''Step
481−#endif
482−
483−o_1_space_reduce_read_split :: BenchEnv -> [Benchmark]
484−o_1_space_reduce_read_split env =
485− [ bgroup "reduce/read"
486− [ mkBench "S.parseMany (PR.sliceSepBy (== lf) FL.drain)" env
487− $ \inh _ -> parseManySepBy inh
488− , mkBench "S.wordsBy isSpace FL.drain" env $ \inh _ ->
489− wordsBy inh
490− , mkBench "S.splitOn (== lf) FL.drain" env $ \inh _ ->
491− splitOn inh
492− , mkBench "S.splitOnSuffix (== lf) FL.drain" env $ \inh _ ->
493− splitOnSuffix inh
494− , mkBench "S.splitWithSuffix (== lf) FL.drain" env $ \inh _ ->
495− splitWithSuffix inh
496− , mkBench "S.splitOnSeq \"\" FL.drain" env $ \inh _ ->
497− splitOnSeq "" inh
498− , mkBench "S.splitOnSuffixSeq \"\" FL.drain" env $ \inh _ ->
499− splitOnSuffixSeq "" inh
500− , mkBench "S.splitOnSeq \"\\n\" FL.drain" env $ \inh _ ->
501− splitOnSeq "\n" inh
502− , mkBench "S.splitOnSuffixSeq \"\\n\" FL.drain" env $ \inh _ ->
503− splitOnSuffixSeq "\n" inh
504− , mkBench "S.splitOnSeq \"a\" FL.drain" env $ \inh _ ->
505− splitOnSeq "a" inh
506− , mkBench "S.splitOnSeq \"\\r\\n\" FL.drain" env $ \inh _ ->
507− splitOnSeq "\r\n" inh
508− , mkBench "S.splitOnSuffixSeq \"\\r\\n\" FL.drain" env $ \inh _ ->
509− splitOnSuffixSeq "\r\n" inh
510− , mkBench "S.splitOnSeq \"aa\" FL.drain" env $ \inh _ ->
511− splitOnSeq "aa" inh
512− , mkBench "S.splitOnSeq \"aaaa\" FL.drain" env $ \inh _ ->
513− splitOnSeq "aaaa" inh
514− , mkBench "S.splitOnSeq \"abcdefgh\" FL.drain" env $ \inh _ ->
515− splitOnSeq "abcdefgh" inh
516− , mkBench "S.splitOnSeq \"abcdefghi\" FL.drain" env $ \inh _ ->
517− splitOnSeq "abcdefghi" inh
518− , mkBench "S.splitOnSeq \"catcatcatcatcat\" FL.drain" env $ \inh _ ->
519− splitOnSeq "catcatcatcatcat" inh
520− , mkBench "S.splitOnSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
521− env $ \inh _ -> splitOnSeq "abcdefghijklmnopqrstuvwxyz" inh
522− , mkBench "S.splitOnSeq 100k long pattern"
523− env $ \inh _ -> splitOnSeq100k inh
524− , mkBenchSmall "S.splitOnSuffixSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
525− env $ \inh _ -> splitOnSuffixSeq "abcdefghijklmnopqrstuvwxyz" inh
526− ]
527− ]
528−
529−-- | Split on a character sequence.
530−splitOnSeqUtf8 :: String -> Handle -> IO Int
531−splitOnSeqUtf8 str inh =
532− (S.length $ IP.splitOnSeq (A.fromList str) FL.drain
533− $ IUS.decodeUtf8Arrays
534− $ IFH.toChunks inh) -- >>= print
535−
536−o_1_space_reduce_toChunks_split :: BenchEnv -> [Benchmark]
537−o_1_space_reduce_toChunks_split env =
538− [ bgroup "reduce/toChunks"
539− [ mkBenchSmall ("S.splitOnSeqUtf8 \"abcdefgh\" FL.drain "
540− ++ ". US.decodeUtf8Arrays") env $ \inh _ ->
541− splitOnSeqUtf8 "abcdefgh" inh
542− , mkBenchSmall "S.splitOnSeqUtf8 \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
543− env $ \inh _ -> splitOnSeqUtf8 "abcdefghijklmnopqrstuvwxyz" inh
544− ]
545− ]
546−
547−-------------------------------------------------------------------------------
548−--
549−-------------------------------------------------------------------------------
550−
551allBenchmarks :: BenchEnv -> [Benchmark]
386allBenchmarks :: BenchEnv -> [Benchmark]
552allBenchmarks env = Prelude.concat
387allBenchmarks env = Prelude.concat
553 [ o_1_space_read_chunked env
388 [ o_1_space_read_chunked env
554 , o_1_space_reduce_read env
389 , o_1_space_reduce_read env
555 , o_1_space_reduce_toBytes env
390 , o_1_space_reduce_toBytes env
556 , o_1_space_reduce_read_grouped env
391 , o_1_space_reduce_read_grouped env
557− , o_1_space_reduce_read_split env
392+ -- , o_1_space_reduce_read_split env
558− , o_1_space_reduce_toChunks_split env
393+ -- , o_1_space_reduce_toChunks_split env
559 ]
394 ]
benchmark/Streamly/Benchmark/Prelude/Serial.hs+4−2
@@ -18,8 +18,9 @@ import qualified Serial.Transformation2 as Transformation2
18import qualified Serial.Transformation3 as Transformation3
18import qualified Serial.Transformation3 as Transformation3
19import qualified Serial.Nested as Nested
19import qualified Serial.Nested as Nested
20import qualified Serial.Exceptions as Exceptions
20import qualified Serial.Exceptions as Exceptions
21+import qualified Serial.Split as Split
21
22
22−import Gauge
23+import Gauge hiding (env)
23import Streamly.Benchmark.Common
24import Streamly.Benchmark.Common
24
25
25import Streamly.Benchmark.CommonH
26import Streamly.Benchmark.CommonH
@@ -39,7 +40,8 @@ main = do
39 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
40 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
40 env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
41 env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
41 value `seq` runMode (mode cfg) cfg benches (allBenchmarks value <>
42 value `seq` runMode (mode cfg) cfg benches (allBenchmarks value <>
42− Exceptions.allBenchmarks env)
43+ Exceptions.allBenchmarks env <>
44+ Split.allBenchmarks env)
43 where
45 where
44
46
45 allBenchmarks size = Prelude.concat
47 allBenchmarks size = Prelude.concat
benchmark/streamly-benchmarks.cabal+1
@@ -166,6 +166,7 @@ benchmark Prelude.Serial
166 , Serial.Transformation3
166 , Serial.Transformation3
167 , Serial.Nested
167 , Serial.Nested
168 , Serial.Exceptions
168 , Serial.Exceptions
169+ , Serial.Split
169 ,Streamly.Benchmark.CommonH
170 ,Streamly.Benchmark.CommonH
170 if impl(ghcjs)
171 if impl(ghcjs)
171 buildable: False
172 buildable: False