Add simple bench suite for Unicode.Utf8

This commit is contained in:
Adithya Kumar 2021-07-30 16:00:33 +05:30 committed by Adithya Kumar
parent f2906948da
commit 7830df9314
3 changed files with 63 additions and 0 deletions

View File

@ -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
]
]

View File

@ -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

View File

@ -109,6 +109,7 @@ targets () {
INDIVIDUAL_TARGETS="\
Data.Unfold \
Unicode.Stream \
Unicode.Utf8 \
FileSystem.Handle \
`test_only FileSystem.Event` \
`test_only Network.Socket` \