mirror of
https://github.com/composewell/streamly.git
synced 2024-09-21 00:20:08 +03:00
Add simple bench suite for Unicode.Utf8
This commit is contained in:
parent
f2906948da
commit
7830df9314
55
benchmark/Streamly/Benchmark/Unicode/Utf8.hs
Normal file
55
benchmark/Streamly/Benchmark/Unicode/Utf8.hs
Normal 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
|
||||
]
|
||||
]
|
@ -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
|
||||
|
@ -109,6 +109,7 @@ targets () {
|
||||
INDIVIDUAL_TARGETS="\
|
||||
Data.Unfold \
|
||||
Unicode.Stream \
|
||||
Unicode.Utf8 \
|
||||
FileSystem.Handle \
|
||||
`test_only FileSystem.Event` \
|
||||
`test_only Network.Socket` \
|
||||
|
Loading…
Reference in New Issue
Block a user