Created
March 8, 2024 15:06
-
-
Save mpickering/a41afe485b309eb694ade02178f0a9d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables, TemplateHaskell, NoMonomorphismRestriction #-} | |
module Main where | |
-- The testing library | |
import Test.Tasty.Bench | |
import qualified TEXT1.Data.Text as TEXT1 | |
import qualified TEXT1.Data.Text.IO as TEXT1 | |
import qualified TEXT2.Data.Text as TEXT2 | |
import qualified TEXT2.Data.Text.IO as TEXT2 | |
import Control.DeepSeq | |
data InputEnv a = InputEnv { lorem :: !a } | |
instance NFData (InputEnv a) where | |
rnf InputEnv{} = () | |
type T1Env = InputEnv TEXT1.Text | |
type T2Env = InputEnv TEXT2.Text | |
mkBench :: T1Env -> T2Env -> (TEXT1.Text -> a) -> (TEXT2.Text -> b) -> [Benchmark] | |
mkBench t1env t2env t1 t2 = | |
[ bench "t1" $ whnf t1 (lorem t1env) | |
, bench "t2" $ whnf t2 (lorem t2env) ] | |
main = | |
defaultMain . (:[]) $ | |
env (InputEnv <$> TEXT1.readFile "lorem.txt") $ \t1env -> | |
env (InputEnv <$> TEXT2.readFile "lorem.txt") $ \t2env -> | |
let mk_bench = mkBench t1env t2env | |
in bgroup "text" | |
[ bgroup "Reverse" (mk_bench TEXT1.reverse TEXT2.reverse) | |
, bgroup "Length" (mk_bench TEXT1.length TEXT2.length) | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables, TemplateHaskell, NoMonomorphismRestriction, DataKinds, KindSignatures, FlexibleInstances, TypeApplications #-} | |
module Main where | |
-- The testing library | |
import Test.Tasty.Bench | |
import qualified TEXT1.Data.Text as TEXT1 | |
import qualified TEXT1.Data.Text.IO as TEXT1 | |
import qualified TEXT1.Control.DeepSeq as TEXT1 | |
import qualified TEXT2.Data.Text as TEXT2 | |
import qualified TEXT2.Data.Text.IO as TEXT2 | |
import qualified TEXT2.Control.DeepSeq as TEXT2 | |
import Control.DeepSeq | |
data Scope = T1 | T2 | |
data Env (scope :: Scope) a = Env { lorem :: !a } | |
instance TEXT1.NFData a => NFData (Env T1 a) where | |
rnf (Env x) = TEXT1.rnf x | |
instance TEXT2.NFData a => NFData (Env T2 a) where | |
rnf (Env x) = TEXT2.rnf x | |
type T1Env = Env T1 TEXT1.Text | |
type T2Env = Env T2 TEXT2.Text | |
mkBench :: (NFData a, NFData b) => T1Env -> T2Env -> (TEXT1.Text -> a) -> (TEXT2.Text -> b) -> [Benchmark] | |
mkBench t1env t2env t1 t2 = | |
[ bench "t1" $ nf t1 (lorem t1env) | |
, bench "t2" $ nf t2 (lorem t2env) ] | |
main = | |
defaultMain . (:[]) $ | |
env (Env <$> TEXT1.readFile "lorem.txt") $ \t1env -> | |
env (Env <$> TEXT2.readFile "lorem.txt") $ \t2env -> | |
let mk_bench x y = mkBench t1env t2env (Env @T1 . x) (Env @T2. y) | |
in bgroup "text" | |
[ bgroup "Reverse" (mk_bench TEXT1.reverse TEXT2.reverse) | |
, bgroup "Length" (mk_bench TEXT1.length TEXT2.length) | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: 3.0 | |
name: testing-text | |
version: 0.1.0.0 | |
-- synopsis: | |
-- description: | |
license: BSD-3-Clause | |
license-file: LICENSE | |
author: Matthew Pickering | |
maintainer: matthewtpickering@gmail.com | |
-- copyright: | |
build-type: Simple | |
extra-doc-files: CHANGELOG.md | |
-- extra-source-files: | |
common warnings | |
ghc-options: -Wall | |
test-suite testing-text-test | |
import: warnings | |
default-language: Haskell2010 | |
-- other-modules: | |
-- other-extensions: | |
type: exitcode-stdio-1.0 | |
hs-source-dirs: test | |
main-is: Main.hs | |
build-depends: base ^>=4.18.0.0, QuickCheck, tasty-quickcheck, tasty | |
private-build-depends: TEXT1 with (text == 1.2.*), TEXT2 with (text == 2.*) | |
benchmark testing-text-benchmarks | |
import: warnings | |
default-language: Haskell2010 | |
-- other-modules: | |
-- other-extensions: | |
type: exitcode-stdio-1.0 | |
hs-source-dirs: bench/ | |
main-is: Main.hs | |
build-depends: base ^>=4.18.0.0, tasty-bench, tasty, deepseq | |
private-build-depends: TEXT1 with (text == 1.2.*), TEXT2 with (text == 2.*) | |
benchmark testing-text-benchmarks-nfdata | |
import: warnings | |
default-language: Haskell2010 | |
-- other-modules: | |
-- other-extensions: | |
type: exitcode-stdio-1.0 | |
hs-source-dirs: bench/ | |
main-is: MainNFData.hs | |
build-depends: base ^>=4.18.0.0, tasty-bench, tasty, deepseq | |
private-build-depends: TEXT1 with (text == 1.2.*, pretty, containers, template-haskell, bytestring, binary, deepseq), TEXT2 with (text == 2.*, pretty, template-haskell, bytestring, binary, containers, deepseq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment