Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions benchmark/Streamly/Benchmark/Data/Scanl/Combinators.hs

Large diffs are not rendered by default.

120 changes: 75 additions & 45 deletions benchmark/Streamly/Benchmark/Data/Scanl/Container.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
-- License : MIT
-- Maintainer : streamly@composewell.com

#ifdef __HADDOCK_VERSION__
#undef INSPECTION
#endif

#ifdef INSPECTION
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
#endif

{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskellQuotes #-}

{-# OPTIONS_GHC -Wno-orphans #-}

-- Benchmarks for operations exported from Streamly.Internal.Data.Scanl.Container.
module Scanl.Container (benchmarks) where

-- import Data.IntSet (IntSet)
import Data.IORef (IORef, newIORef, readIORef, modifyIORef)
import Data.Map.Strict (Map)
-- import Data.Set (Set)
-- import Data.STRef (STRef)
import Streamly.Internal.Data.Scanl (Scanl(..))
import Streamly.Internal.Data.Stream (Stream)
-- import Streamly.Internal.Data.Tuple.Strict (Tuple', Tuple3')
import System.IO.Unsafe (unsafePerformIO)
import System.Random (randomRIO)

Expand All @@ -34,15 +31,10 @@ import qualified Streamly.Internal.Data.Fold as FL
import qualified Streamly.Internal.Data.Scanl as Scanl
import qualified Streamly.Internal.Data.Stream as Stream

import Fusion.Plugin.Types
import Streamly.Benchmark.Common
import Test.Tasty.Bench

#ifdef INSPECTION
import GHC.Types (SPEC(..))
import Streamly.Internal.Data.Stream (Step(..))
import Test.Inspection
#endif

-------------------------------------------------------------------------------
-- Helpers
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -91,62 +83,91 @@ getScanl k = do
-- Set operations
-------------------------------------------------------------------------------

{-# INLINE toSet #-}
-- {-# ANN toSet (PermitTypes [''Int,''Set,''STRef,''(,)]) #-}
{-# ANN toSet (PermitTypeClasses []) #-}
{-# ANN toSet (MaxCoreSize 1000) #-}
{-# NOINLINE toSet #-}
toSet :: Int -> IO ()
toSet n = withPostscanl n Scanl.toSet

{-# INLINE toIntSet #-}
-- {-# ANN toIntSet (PermitTypes [''Int,''STRef,''IntSet,''(,)]) #-}
{-# ANN toIntSet (PermitTypeClasses []) #-}
{-# ANN toIntSet (MaxCoreSize 1000) #-}
{-# NOINLINE toIntSet #-}
toIntSet :: Int -> IO ()
toIntSet n = withPostscanl n Scanl.toIntSet

{-# INLINE countDistinct #-}
-- {-# ANN countDistinct (PermitTypes [''Int,''STRef,''Set,''(,)]) #-}
{-# ANN countDistinct (PermitTypeClasses []) #-}
{-# ANN countDistinct (MaxCoreSize 1000) #-}
{-# NOINLINE countDistinct #-}
countDistinct :: Int -> IO ()
countDistinct n = withPostscanl n Scanl.countDistinct

{-# INLINE countDistinctInt #-}
-- {-# ANN countDistinctInt (PermitTypes [''Int,''STRef,''IntSet,''(,)]) #-}
{-# ANN countDistinctInt (PermitTypeClasses []) #-}
{-# ANN countDistinctInt (MaxCoreSize 1000) #-}
{-# NOINLINE countDistinctInt #-}
countDistinctInt :: Int -> IO ()
countDistinctInt n = withPostscanl n Scanl.countDistinctInt

{-# INLINE nub #-}
-- {-# ANN nub (PermitTypes [''Int,''STRef,''Set,''Maybe,''Tuple',''(,)]) #-}
{-# ANN nub (PermitTypeClasses []) #-}
{-# ANN nub (MaxCoreSize 1000) #-}
{-# NOINLINE nub #-}
nub :: Int -> IO ()
nub n = withPostscanl n Scanl.nub

{-# INLINE nubInt #-}
-- {-# ANN nubInt (PermitTypes [''Int,''STRef,''IntSet,''(,)]) #-}
{-# ANN nubInt (PermitTypeClasses []) #-}
{-# ANN nubInt (MaxCoreSize 1000) #-}
{-# NOINLINE nubInt #-}
nubInt :: Int -> IO ()
nubInt n = withPostscanl n Scanl.nubInt

-------------------------------------------------------------------------------
-- Demultiplexing
-------------------------------------------------------------------------------

{-# INLINE demuxIOOneShot #-}
-- {-# ANN demuxIOOneShot (PermitTypes [''Int,''STRef,''IORef,''Map,''Scanl,
-- ''FL.Step, ''Scanl.Step,''(,)]) #-}
{-# ANN demuxIOOneShot (PermitTypeClasses []) #-}
{-# ANN demuxIOOneShot (MaxCoreSize 2000) #-}
{-# NOINLINE demuxIOOneShot #-}
demuxIOOneShot :: Int -> IO ()
demuxIOOneShot len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl (Scanl.demuxIO (getKey 64) getScanl)

{-# INLINE demuxIOSum #-}
-- {-# ANN demuxIOSum (PermitTypes
-- [''Int,''STRef,''IORef,''Map,''Scanl,''FL.Step,''Scanl.Step,''(,)]) #-}
{-# ANN demuxIOSum (PermitTypeClasses []) #-}
{-# ANN demuxIOSum (MaxCoreSize 1000) #-}
{-# NOINLINE demuxIOSum #-}
demuxIOSum :: Int -> IO ()
demuxIOSum len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl
(Scanl.demuxIO (getKey 64) (const (pure (Just Scanl.sum))))

#ifdef INSPECTION
inspect $ 'demuxIOSum `hasNoType` ''SPEC
#endif

{-# INLINE demuxSum #-}
-- {-# ANN demuxSum (PermitTypes [''Int,''STRef,''IO,''Map,''Scanl,''FL.Step,''Scanl.Step,''(,)]) #-}
{-# ANN demuxSum (PermitTypeClasses []) #-}
{-# ANN demuxSum (MaxCoreSize 1000) #-}
{-# NOINLINE demuxSum #-}
demuxSum :: Int -> IO ()
demuxSum len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl
(Scanl.demux (getKey 64) (const (pure (Just Scanl.sum))))

{-# INLINE demuxGenericSum #-}
-- {-# ANN demuxGenericSum (PermitTypes
-- [''Int,''STRef,''Map,''Maybe,''Scanl,''FL.Step,''Scanl.Step,''(,)]) #-}
{-# ANN demuxGenericSum (PermitTypeClasses []) #-}
{-# ANN demuxGenericSum (MaxCoreSize 1000) #-}
{-# NOINLINE demuxGenericSum #-}
demuxGenericSum :: Int -> IO ()
demuxGenericSum len =
withStream len $
Expand All @@ -155,7 +176,11 @@ demuxGenericSum len =
(Scanl.demuxGeneric (getKey 64) (const (pure (Just Scanl.sum)))
:: Scanl IO Int (IO (Map Int Int), Maybe (Int, Int)))

{-# INLINE demuxGenericIOSum #-}
-- {-# ANN demuxGenericIOSum (PermitTypes
-- [''Int,''STRef,''Map,''Maybe,''Scanl,''FL.Step,''Scanl.Step,''(,)]) #-}
{-# ANN demuxGenericIOSum (PermitTypeClasses []) #-}
{-# ANN demuxGenericIOSum (MaxCoreSize 1000) #-}
{-# NOINLINE demuxGenericIOSum #-}
demuxGenericIOSum :: Int -> IO ()
demuxGenericIOSum len =
withStream len $
Expand All @@ -168,38 +193,40 @@ demuxGenericIOSum len =
-- Classifying
-------------------------------------------------------------------------------

{-# INLINE classifyLimitedSum #-}
-- {-# ANN classifyLimitedSum (PermitTypes [''Int,''STRef,''IORef,''Map,''Set,''Tuple',''(,)]) #-}
{-# ANN classifyLimitedSum (PermitTypeClasses []) #-}
{-# ANN classifyLimitedSum (MaxCoreSize 1000) #-}
{-# NOINLINE classifyLimitedSum #-}
classifyLimitedSum :: Int -> IO ()
classifyLimitedSum len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl (Scanl.classifyIO (getKey 64) (limitedSum 100))

#ifdef INSPECTION
inspect $ 'classifyLimitedSum `hasNoType` ''FL.Step
inspect $ 'classifyLimitedSum `hasNoType` ''SPEC
#endif

{-# INLINE classifyIOSum #-}
-- {-# ANN classifyIOSum (PermitTypes [''Int,''STRef,''IORef,''Map,''Tuple',''(,)]) #-}
{-# ANN classifyIOSum (PermitTypeClasses []) #-}
{-# ANN classifyIOSum (MaxCoreSize 1000) #-}
{-# NOINLINE classifyIOSum #-}
classifyIOSum :: Int -> IO ()
classifyIOSum len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl (Scanl.classifyIO (getKey 64) Scanl.sum)

#ifdef INSPECTION
inspect $ 'classifyIOSum `hasNoType` ''FL.Step
inspect $ 'classifyIOSum `hasNoType` ''SPEC
#endif

{-# INLINE classifySum #-}
-- {-# ANN classifySum (PermitTypes [''Int,''STRef,''Map,''Tuple',''(,)]) #-}
{-# ANN classifySum (PermitTypeClasses []) #-}
{-# ANN classifySum (MaxCoreSize 1000) #-}
{-# NOINLINE classifySum #-}
classifySum :: Int -> IO ()
classifySum len =
withStream len $
Stream.fold FL.drain
. Stream.postscanl (Scanl.classify (getKey 64) Scanl.sum)

{-# INLINE classifyGenericSum #-}
-- {-# ANN classifyGenericSum (PermitTypes [''Int,''STRef,''Map,''Maybe,''Set,''Tuple',''Tuple3',''(,)]) #-}
{-# ANN classifyGenericSum (PermitTypeClasses []) #-}
{-# ANN classifyGenericSum (MaxCoreSize 1000) #-}
{-# NOINLINE classifyGenericSum #-}
classifyGenericSum :: Int -> IO ()
classifyGenericSum len =
withStream len $
Expand All @@ -208,7 +235,10 @@ classifyGenericSum len =
(Scanl.classifyGeneric (getKey 64) Scanl.sum
:: Scanl IO Int (IO (Map Int Int), Maybe (Int, Int)))

{-# INLINE classifyGenericIOSum #-}
-- {-# ANN classifyGenericIOSum (PermitTypes [''Int,''STRef,''Map,''Maybe,''Set,''Tuple',''Tuple3',''(,)]) #-}
{-# ANN classifyGenericIOSum (PermitTypeClasses []) #-}
{-# ANN classifyGenericIOSum (MaxCoreSize 1000) #-}
{-# NOINLINE classifyGenericIOSum #-}
classifyGenericIOSum :: Int -> IO ()
classifyGenericIOSum len =
withStream len $
Expand Down
Loading
Loading