Skip to content

Commit ba62f0d

Browse files
authored
Benchmarks: Switch from gauge to tasty-bench (#2615)
1 parent 4f185b9 commit ba62f0d

File tree

13 files changed

+59
-56
lines changed

13 files changed

+59
-56
lines changed

dhall/benchmark/deep-nested-large-record/Main.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
module Main (main) where
33

4-
import Data.Void (Void)
5-
import Gauge (defaultMain)
4+
import Data.Void (Void)
5+
import Test.Tasty.Bench
66

77
import qualified Data.Sequence as Seq
88
import qualified Dhall.Core as Core
99
import qualified Dhall.Import as Import
1010
import qualified Dhall.TypeCheck as TypeCheck
11-
import qualified Gauge
1211

1312
dhallPreludeImport :: Core.Import
1413
dhallPreludeImport = Core.Import
@@ -22,8 +21,8 @@ dhallPreludeImport = Core.Import
2221
}
2322
}
2423

25-
issue412 :: Core.Expr s Void -> Gauge.Benchmarkable
26-
issue412 prelude = Gauge.whnf TypeCheck.typeOf expr
24+
issue412 :: Core.Expr s Void -> Benchmarkable
25+
issue412 prelude = whnf TypeCheck.typeOf expr
2726
where
2827
expr
2928
= Core.Let (Core.Binding Nothing "prelude" Nothing Nothing Nothing prelude)
@@ -34,8 +33,8 @@ issue412 prelude = Gauge.whnf TypeCheck.typeOf expr
3433
little = Core.makeFieldSelection "little"
3534
foo = Core.makeFieldSelection "Foo"
3635

37-
unionPerformance :: Core.Expr s Void -> Gauge.Benchmarkable
38-
unionPerformance prelude = Gauge.whnf TypeCheck.typeOf expr
36+
unionPerformance :: Core.Expr s Void -> Benchmarkable
37+
unionPerformance prelude = whnf TypeCheck.typeOf expr
3938
where
4039
expr =
4140
Core.Let
@@ -64,10 +63,10 @@ unionPerformance prelude = Gauge.whnf TypeCheck.typeOf expr
6463
main :: IO ()
6564
main =
6665
defaultMain
67-
[ Gauge.env prelude $ \p ->
68-
Gauge.bgroup "Prelude"
69-
[ Gauge.bench "issue 412" (issue412 p)
70-
, Gauge.bench "union performance" (unionPerformance p)
66+
[ env prelude $ \p ->
67+
bgroup "Prelude"
68+
[ bench "issue 412" (issue412 p)
69+
, bench "union performance" (unionPerformance p)
7170
]
7271
]
7372
where prelude = Import.load (Core.Embed dhallPreludeImport)

dhall/benchmark/parser/Main.hs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE OverloadedStrings #-}
23

34
module Main where
45

56
import Control.Exception (throw)
67
import Control.Monad (forM)
7-
import Data.Map (Map, foldrWithKey, singleton, unions)
8+
import Data.Map (Map)
9+
import Data.Text (Text)
810
import Data.Void (Void)
9-
import Gauge (bench, bgroup, defaultMain, env, nf, whnf)
10-
11-
import System.Directory
11+
import Test.Tasty.Bench
1212

1313
import qualified Data.ByteString.Lazy
14-
import qualified Data.Text as T
15-
import qualified Data.Text.IO as TIO
14+
import qualified Data.Map as Map
15+
import qualified Data.Text as Text
16+
import qualified Data.Text.IO
1617
import qualified Dhall.Binary
1718
import qualified Dhall.Core as Dhall
1819
import qualified Dhall.Parser as Dhall
19-
import qualified Gauge
20+
import qualified System.Directory as Directory
2021

21-
type PreludeFiles = Map FilePath T.Text
22+
type PreludeFiles = Map FilePath Text
2223

2324
loadPreludeFiles :: IO PreludeFiles
2425
loadPreludeFiles = loadDirectory "./dhall-lang/Prelude"
2526
where
2627
loadDirectory :: FilePath -> IO PreludeFiles
2728
loadDirectory dir =
28-
withCurrentDirectory dir $ do
29-
files <- getCurrentDirectory >>= listDirectory
29+
Directory.withCurrentDirectory dir $ do
30+
files <- Directory.getCurrentDirectory >>= Directory.listDirectory
3031
results <- forM files $ \file -> do
31-
file' <- makeAbsolute file
32-
doesExist <- doesFileExist file'
32+
file' <- Directory.makeAbsolute file
33+
doesExist <- Directory.doesFileExist file'
3334
if doesExist
3435
then loadFile file'
3536
else loadDirectory file'
36-
pure $ unions results
37+
pure $ Map.unions results
3738

3839
loadFile :: FilePath -> IO PreludeFiles
39-
loadFile path = singleton path <$> TIO.readFile path
40+
loadFile path = Map.singleton path <$> Data.Text.IO.readFile path
4041

41-
benchParser :: PreludeFiles -> Gauge.Benchmark
42+
benchParser :: PreludeFiles -> Benchmark
4243
benchParser =
4344
bgroup "exprFromText"
44-
. foldrWithKey (\name expr -> (benchExprFromText name expr :)) []
45+
. Map.foldrWithKey (\name expr -> (benchExprFromText name expr :)) []
4546

46-
benchExprFromText :: String -> T.Text -> Gauge.Benchmark
47-
benchExprFromText name expr =
47+
benchExprFromText :: String -> Text -> Benchmark
48+
benchExprFromText name !expr =
4849
bench name $ whnf (Dhall.exprFromText "(input)") expr
4950

50-
benchExprFromBytes
51-
:: String -> Data.ByteString.Lazy.ByteString -> Gauge.Benchmark
51+
benchExprFromBytes :: String -> Data.ByteString.Lazy.ByteString -> Benchmark
5252
benchExprFromBytes name bs = bench name (nf f bs)
5353
where
5454
f bytes =
5555
case Dhall.Binary.decodeExpression bytes of
5656
Left exception -> error (show exception)
5757
Right expression -> expression :: Dhall.Expr Void Dhall.Import
5858

59-
benchNfExprFromText :: String -> T.Text -> Gauge.Benchmark
60-
benchNfExprFromText name expr =
59+
benchNfExprFromText :: String -> Text -> Benchmark
60+
benchNfExprFromText name !expr =
6161
bench name $ nf (either throw id . Dhall.exprFromText "(input)") expr
6262

6363
main :: IO ()
@@ -71,20 +71,21 @@ main = do
7171
]
7272
, env kubernetesExample $
7373
benchExprFromBytes "Kubernetes/Binary"
74-
, benchExprFromText "Long variable names" (T.replicate 1000000 "x")
75-
, benchExprFromText "Large number of function arguments" (T.replicate 10000 "x ")
76-
, benchExprFromText "Long double-quoted strings" ("\"" <> T.replicate 1000000 "x" <> "\"")
77-
, benchExprFromText "Long single-quoted strings" ("''" <> T.replicate 1000000 "x" <> "''")
78-
, benchExprFromText "Whitespace" (T.replicate 1000000 " " <> "x")
79-
, benchExprFromText "Line comment" ("x -- " <> T.replicate 1000000 " ")
80-
, benchExprFromText "Block comment" ("x {- " <> T.replicate 1000000 " " <> "-}")
74+
, benchExprFromText "Long variable names" (Text.replicate 1000000 "x")
75+
, benchExprFromText "Large number of function arguments" (Text.replicate 10000 "x ")
76+
, benchExprFromText "Long double-quoted strings" ("\"" <> Text.replicate 1000000 "x" <> "\"")
77+
, benchExprFromText "Long single-quoted strings" ("''" <> Text.replicate 1000000 "x" <> "''")
78+
, benchExprFromText "Whitespace" (Text.replicate 1000000 " " <> "x")
79+
, benchExprFromText "Line comment" ("x -- " <> Text.replicate 1000000 " ")
80+
, benchExprFromText "Block comment" ("x {- " <> Text.replicate 1000000 " " <> "-}")
8181
, benchExprFromText "Deeply nested parentheses" "((((((((((((((((x))))))))))))))))"
8282
, benchParser prelude
8383
, env cpkgExample $
8484
benchNfExprFromText "CPkg/Text"
8585
]
86-
where cpkgExample = TIO.readFile "benchmark/examples/cpkg.dhall"
87-
issue108Text = TIO.readFile "benchmark/examples/issue108.dhall"
88-
issue108Bytes = Data.ByteString.Lazy.readFile "benchmark/examples/issue108.dhall.bin"
89-
issues = (,) <$> issue108Text <*> issue108Bytes
90-
kubernetesExample = Data.ByteString.Lazy.readFile "benchmark/examples/kubernetes.dhall.bin"
86+
where
87+
cpkgExample = Data.Text.IO.readFile "benchmark/parser/examples/cpkg.dhall"
88+
issue108Text = Data.Text.IO.readFile "benchmark/parser/examples/issue108.dhall"
89+
issue108Bytes = Data.ByteString.Lazy.readFile "benchmark/parser/examples/issue108.dhallb"
90+
issues = (,) <$> issue108Text <*> issue108Bytes
91+
kubernetesExample = Data.ByteString.Lazy.readFile "benchmark/parser/examples/kubernetes.dhallb"

0 commit comments

Comments
 (0)