diff --git a/benchmark/Streamly/Benchmark/Unicode/Utf8.hs b/benchmark/Streamly/Benchmark/Unicode/Utf8.hs new file mode 100644 index 000000000..10acc3972 --- /dev/null +++ b/benchmark/Streamly/Benchmark/Unicode/Utf8.hs @@ -0,0 +1,55 @@ +-- +-- Module : Streamly.Unicode.Utf8 +-- Copyright : (c) 2021 Composewell Technologies +-- License : BSD-3-Clause +-- Maintainer : streamly@composewell.com +-- Stability : experimental +-- Portability : GHC + +-------------------------------------------------------------------------------- +-- Imports +-------------------------------------------------------------------------------- + +import Data.Char (chr) +import Streamly.Internal.Unicode.Utf8 (Utf8) + +import Gauge hiding (env) +import Streamly.Benchmark.Common + +import qualified Streamly.Internal.Unicode.Utf8 as Utf8 + +-------------------------------------------------------------------------------- +-- Utilities +-------------------------------------------------------------------------------- + +moduleName :: String +moduleName = "Unicode.Stream" + +-------------------------------------------------------------------------------- +-- Benchmarks +-------------------------------------------------------------------------------- + +{-# INLINE pack #-} +pack :: Int -> Utf8 +pack i = Utf8.pack $ chr <$> [1 .. i] + +{-# INLINE packUnpack #-} +packUnpack :: Int -> String +packUnpack = Utf8.unpack . pack + +-------------------------------------------------------------------------------- +-- Main function +-------------------------------------------------------------------------------- + +main :: IO () +main = runWithCLIOpts defaultStreamSize allBenchmarks + + where + + allBenchmarks value = + [ bgroup + moduleName + [ bench "pack" $ nf pack value + , bench "pack + unpack" $ nf packUnpack value + ] + ] diff --git a/benchmark/streamly-benchmarks.cabal b/benchmark/streamly-benchmarks.cabal index 0f52d9bca..05c89da25 100644 --- a/benchmark/streamly-benchmarks.cabal +++ b/benchmark/streamly-benchmarks.cabal @@ -497,8 +497,15 @@ benchmark FileSystem.Handle ------------------------------------------------------------------------------- -- Unicode Benchmarks ------------------------------------------------------------------------------- + benchmark Unicode.Stream import: bench-options type: exitcode-stdio-1.0 hs-source-dirs: Streamly/Benchmark/Unicode main-is: Stream.hs + +benchmark Unicode.Utf8 + import: bench-options + type: exitcode-stdio-1.0 + hs-source-dirs: Streamly/Benchmark/Unicode + main-is: Utf8.hs diff --git a/bin/targets.sh b/bin/targets.sh index 133c2d912..fc285d595 100644 --- a/bin/targets.sh +++ b/bin/targets.sh @@ -109,6 +109,7 @@ targets () { INDIVIDUAL_TARGETS="\ Data.Unfold \ Unicode.Stream \ + Unicode.Utf8 \ FileSystem.Handle \ `test_only FileSystem.Event` \ `test_only Network.Socket` \