Skip to content

Commit f0baaf8

Browse files
committed
Make benchmarks compatible with text-builder-1.0
1 parent efbfd88 commit f0baaf8

File tree

8 files changed

+37
-34
lines changed

8 files changed

+37
-34
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ Let's benchmark builders, which concatenate all `Char` from `minBound` to `maxBo
5959
```haskell
6060
#!/usr/bin/env cabal
6161
{- cabal:
62-
build-depends: base, tasty-bench, text, text-builder, text-builder-linear
62+
build-depends: base, tasty-bench, text, text-builder >= 1.0, text-builder-linear
6363
ghc-options: -O2
6464
-}
6565

6666
import qualified Data.Text as T
6767
import qualified Data.Text.Lazy as TL
6868
import qualified Data.Text.Lazy.Builder as TLB
69-
import qualified Text.Builder as TB
69+
import qualified TextBuilder as TB
7070
import qualified Data.Text.Builder.Linear as TBL
7171
import System.Environment (getArgs)
7272
import Test.Tasty.Bench
@@ -79,7 +79,7 @@ main :: IO ()
7979
main = defaultMain
8080
[ mkBench "text, lazy" TLB.singleton (fromIntegral . TL.length . TLB.toLazyText)
8181
, mkBench "text, strict" TLB.singleton (T.length . TL.toStrict . TLB.toLazyText)
82-
, mkBench "text-builder" TB.char (T.length . TB.run)
82+
, mkBench "text-builder" TB.char (T.length . TB.toText)
8383
, mkBench "text-builder-linear" TBL.fromChar (T.length . TBL.runBuilder)
8484
]
8585
```
@@ -117,7 +117,7 @@ The last result corresponds to the current package. We generate a strict
117117
high. Nevertheless, it is already faster than the usual `Text` builder with
118118
strict consumer and does not strain the garbage collector.
119119

120-
Things get very different if we remove `{-# INLINE mkBench #-}`:
120+
As of GHC 9.10, things get very different if we remove `{-# INLINE mkBench #-}`:
121121

122122
```
123123
text, lazy:

bench/BenchChar.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import qualified Data.Text.Internal.Fusion as Fusion
1919
import Test.Tasty.Bench
2020

2121
#ifdef MIN_VERSION_text_builder
22-
import qualified Text.Builder
22+
import qualified TextBuilder
23+
import qualified TextBuilderDev as TextBuilder
2324
#endif
2425

2526
#ifdef MIN_VERSION_bytestring_strict_builder
@@ -44,10 +45,10 @@ benchLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
4445

4546
#ifdef MIN_VERSION_text_builder
4647
benchStrictBuilder Int T.Text
47-
benchStrictBuilder = Text.Builder.run . go mempty
48+
benchStrictBuilder = TextBuilder.toText . go mempty
4849
where
4950
go !acc 0 = acc
50-
go !acc n = let ch = chr n in go (Text.Builder.char ch <> (acc <> Text.Builder.char ch)) (n - 1)
51+
go !acc n = let ch = chr n in go (TextBuilder.char ch <> (acc <> TextBuilder.char ch)) (n - 1)
5152
#endif
5253

5354
#ifdef MIN_VERSION_bytestring_strict_builder
@@ -73,7 +74,7 @@ mkGroupChar n = bgroup (show n)
7374
[ bench "Data.Text.Lazy.Builder" $ nf benchLazyBuilder n
7475
, bench "Data.ByteString.Builder" $ nf benchLazyBuilderBS n
7576
#ifdef MIN_VERSION_text_builder
76-
, bench "Text.Builder" $ nf benchStrictBuilder n
77+
, bench "TextBuilder" $ nf benchStrictBuilder n
7778
#endif
7879
#ifdef MIN_VERSION_bytestring_strict_builder
7980
, bench "ByteString.StrictBuilder" $ nf benchStrictBuilderBS n
@@ -110,13 +111,13 @@ benchCharsLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
110111

111112
#ifdef MIN_VERSION_text_builder
112113
benchCharsStrictBuilder Int T.Text
113-
benchCharsStrictBuilder = Text.Builder.run . go mempty
114+
benchCharsStrictBuilder = TextBuilder.toText . go mempty
114115
where
115116
go !acc 0 = acc
116117
go !acc n = let ch = chr n in go (replicateChar ch <> (acc <> replicateChar ch)) (n - 1)
117118

118119
-- [TODO] Is there a better way?
119-
replicateChar ch = Text.Builder.padFromRight (fromIntegral charCount) ch mempty
120+
replicateChar ch = TextBuilder.padFromRight (fromIntegral charCount) ch mempty
120121
#endif
121122

122123
{- [TODO]
@@ -144,7 +145,7 @@ mkGroupChars n = bgroup (show n)
144145
[ bench "Data.Text.Lazy.Builder" $ nf benchCharsLazyBuilder n
145146
-- , bench "Data.ByteString.Builder" $ nf benchCharsLazyBuilderBS n
146147
#ifdef MIN_VERSION_text_builder
147-
, bench "Text.Builder" $ nf benchCharsStrictBuilder n
148+
, bench "TextBuilder" $ nf benchCharsStrictBuilder n
148149
#endif
149150
-- #ifdef MIN_VERSION_bytestring_strict_builder
150151
-- , bench "ByteString.StrictBuilder" $ nf benchCharsStrictBuilderBS n
@@ -180,13 +181,13 @@ benchPaddingLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
180181

181182
#ifdef MIN_VERSION_text_builder
182183
benchPaddingStrictBuilder Int T.Text
183-
benchPaddingStrictBuilder = Text.Builder.run . go mempty 0
184+
benchPaddingStrictBuilder = TextBuilder.toText . go mempty 0
184185
where
185186
go !acc !_ 0 = acc
186187
go !acc l n =
187188
let ch = chr n
188189
!l' = l + 2 * fromIntegral charCount
189-
in go (Text.Builder.padFromRight l' ch (Text.Builder.padFromLeft (l + fromIntegral charCount) ch acc))
190+
in go (TextBuilder.padFromRight l' ch (TextBuilder.padFromLeft (l + fromIntegral charCount) ch acc))
190191
l'
191192
(n - 1)
192193
#endif
@@ -221,7 +222,7 @@ mkGroupPadding n = bgroup (show n)
221222
[ bench "Data.Text.Lazy.Builder" $ nf benchPaddingLazyBuilder n
222223
-- , bench "Data.ByteString.Builder" $ nf benchPaddingLazyBuilderBS n
223224
#ifdef MIN_VERSION_text_builder
224-
, bench "Text.Builder" $ nf benchPaddingStrictBuilder n
225+
, bench "TextBuilder" $ nf benchPaddingStrictBuilder n
225226
#endif
226227
-- #ifdef MIN_VERSION_bytestring_strict_builder
227228
-- , bench "ByteString.StrictBuilder" $ nf benchPaddingStrictBuilderBS n

bench/BenchDecimal.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Data.Text.Lazy.Builder.Int (decimal)
1414
import Test.Tasty.Bench (Benchmark, bench, bgroup, nf)
1515

1616
#ifdef MIN_VERSION_text_builder
17-
import qualified Text.Builder
17+
import qualified TextBuilder
1818
#endif
1919

2020
#ifdef MIN_VERSION_bytestring_strict_builder
@@ -47,10 +47,10 @@ benchLazyBuilderBS k = B.toStrict . B.toLazyByteString . go mempty
4747

4848
#ifdef MIN_VERSION_text_builder
4949
benchStrictBuilder (Integral a) a Int T.Text
50-
benchStrictBuilder k = Text.Builder.run . go mempty
50+
benchStrictBuilder k = TextBuilder.toText . go mempty
5151
where
5252
go !acc 0 = acc
53-
go !acc n = let i = fromIntegral n * k in go (Text.Builder.decimal i <> (acc <> Text.Builder.decimal i)) (n - 1)
53+
go !acc n = let i = fromIntegral n * k in go (TextBuilder.decimal i <> (acc <> TextBuilder.decimal i)) (n - 1)
5454
{-# SPECIALIZE benchStrictBuilder ∷ Int → Int → T.Text #-}
5555
{-# SPECIALIZE benchStrictBuilder ∷ Integer → Int → T.Text #-}
5656
#endif
@@ -82,7 +82,7 @@ mkBoundedGroup n =
8282
[ bench "Data.Text.Lazy.Builder" $ nf (benchLazyBuilder int) n
8383
, bench "Data.ByteString.Builder" $ nf (benchLazyBuilderBS int) n
8484
#ifdef MIN_VERSION_text_builder
85-
, bench "Text.Builder" $ nf (benchStrictBuilder int) n
85+
, bench "TextBuilder" $ nf (benchStrictBuilder int) n
8686
#endif
8787
#ifdef MIN_VERSION_bytestring_strict_builder
8888
, bench "ByteString.StrictBuilder" $ nf (benchStrictBuilderBS int) n
@@ -136,7 +136,7 @@ mkUnboundedGroup integer n =
136136
[ bench "Data.Text.Lazy.Builder" $ nf (benchLazyBuilder integer) n
137137
, bench "Data.ByteString.Builder" $ nf (benchUnboundedLazyBuilderBS integer) n
138138
#ifdef MIN_VERSION_text_builder
139-
, bench "Text.Builder" $ nf (benchStrictBuilder integer) n
139+
, bench "TextBuilder" $ nf (benchStrictBuilder integer) n
140140
#endif
141141
#ifdef MIN_VERSION_bytestring_strict_builder
142142
, bench "ByteString.StrictBuilder" $ nf (benchStrictBuilderBS integer) n

bench/BenchDouble.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import Data.Text.Lazy.Builder.RealFloat (realFloat)
1515
import Test.Tasty.Bench
1616

1717
#ifdef MIN_VERSION_text_builder
18-
import qualified Text.Builder
18+
import qualified TextBuilder
19+
import qualified TextBuilderDev as TextBuilder
1920
#endif
2021

2122
dbl :: Double
@@ -35,10 +36,10 @@ benchLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
3536

3637
#ifdef MIN_VERSION_text_builder
3738
benchStrictBuilder Int T.Text
38-
benchStrictBuilder = Text.Builder.run . go mempty
39+
benchStrictBuilder = TextBuilder.toText . go mempty
3940
where
4041
go !acc 0 = acc
41-
go !acc n = let d = fromIntegral n * dbl in go (Text.Builder.fixedDouble 17 d <> (acc <> Text.Builder.fixedDouble 17 d)) (n - 1)
42+
go !acc n = let d = fromIntegral n * dbl in go (TextBuilder.doubleFixedPoint 17 d <> (acc <> TextBuilder.doubleFixedPoint 17 d)) (n - 1)
4243
#endif
4344

4445
benchLinearBuilder Int T.Text
@@ -56,7 +57,7 @@ mkGroup n = bgroup (show n)
5657
[ bench "Data.Text.Lazy.Builder" $ nf benchLazyBuilder n
5758
, bench "Data.ByteString.Builder" $ nf benchLazyBuilderBS n
5859
#ifdef MIN_VERSION_text_builder
59-
, bench "Text.Builder" $ nf benchStrictBuilder n
60+
, bench "TextBuilder" $ nf benchStrictBuilder n
6061
#endif
6162
, bench "Data.Text.Builder.Linear" $ nf benchLinearBuilder n
6263
]

bench/BenchHexadecimal.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Data.Text.Lazy.Builder.Int (hexadecimal)
1515
import Test.Tasty.Bench
1616

1717
#ifdef MIN_VERSION_text_builder
18-
import qualified Text.Builder
18+
import qualified TextBuilder
1919
#endif
2020

2121
word :: Word
@@ -35,10 +35,10 @@ benchLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
3535

3636
#ifdef MIN_VERSION_text_builder
3737
benchStrictBuilder Word T.Text
38-
benchStrictBuilder = Text.Builder.run . go mempty
38+
benchStrictBuilder = TextBuilder.toText . go mempty
3939
where
4040
go !acc 0 = acc
41-
go !acc n = let i = n * word in go (Text.Builder.hexadecimal i <> (acc <> Text.Builder.hexadecimal i)) (n - 1)
41+
go !acc n = let i = n * word in go (TextBuilder.hexadecimal i <> (acc <> TextBuilder.hexadecimal i)) (n - 1)
4242
#endif
4343

4444
benchLinearBuilderWord Word T.Text
@@ -63,7 +63,7 @@ mkGroup n = bgroup (show n)
6363
[ bench "Data.Text.Lazy.Builder" $ nf benchLazyBuilder n
6464
, bench "Data.ByteString.Builder" $ nf benchLazyBuilderBS n
6565
#ifdef MIN_VERSION_text_builder
66-
, bench "Text.Builder" $ nf benchStrictBuilder n
66+
, bench "TextBuilder" $ nf benchStrictBuilder n
6767
#endif
6868
, bench "Data.Text.Builder.Linear (Word)" $ nf benchLinearBuilderWord n
6969
, bench "Data.Text.Builder.Linear (Int)" $ nf benchLinearBuilderInt n

bench/BenchText.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Data.Text.Lazy.Builder (toLazyText, fromText)
1515
import Test.Tasty.Bench
1616

1717
#ifdef MIN_VERSION_text_builder
18-
import qualified Text.Builder
18+
import qualified TextBuilder
1919
#endif
2020

2121
#ifdef MIN_VERSION_bytestring_strict_builder
@@ -41,9 +41,9 @@ benchLazyBuilderBS = B.toStrict . B.toLazyByteString . go mempty
4141

4242
#ifdef MIN_VERSION_text_builder
4343
benchStrictBuilder Int T.Text
44-
benchStrictBuilder = Text.Builder.run . go mempty
44+
benchStrictBuilder = TextBuilder.toText . go mempty
4545
where
46-
txtB = Text.Builder.text txt
46+
txtB = TextBuilder.text txt
4747
go !acc 0 = acc
4848
go !acc n = go (txtB <> (acc <> txtB)) (n - 1)
4949
#endif
@@ -72,7 +72,7 @@ mkGroup n = bgroup (show n)
7272
[ bench "Data.Text.Lazy.Builder" $ nf benchLazyBuilder n
7373
, bench "Data.ByteString.Builder" $ nf benchLazyBuilderBS n
7474
#ifdef MIN_VERSION_text_builder
75-
, bench "Text.Builder" $ nf benchStrictBuilder n
75+
, bench "TextBuilder" $ nf benchStrictBuilder n
7676
#endif
7777
#ifdef MIN_VERSION_bytestring_strict_builder
7878
, bench "ByteString.StrictBuilder" $ nf benchStrictBuilderBS n

bench/ParseCsv.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ parseLine xs = M.singleton title (M.singleton size group)
4848
group = case ws of
4949
"Data.Text.Lazy.Builder" -> mempty { grpTextLazy = Just time }
5050
"Data.ByteString.Builder" -> mempty { grpBSLazy = Just time }
51-
"Text.Builder" -> mempty { grpTextStrict = Just time }
51+
"TextBuilder" -> mempty { grpTextStrict = Just time }
5252
"ByteString.StrictBuilder" -> mempty { grpBSStrict = Just time }
5353
"Data.Text.Builder.Linear" -> mempty { grpLinear = Just time }
5454

text-builder-linear.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ benchmark linear-builder-bench
9696
-- NOTE: The following packages are optional, but are not required that
9797
-- often. While they could be guarded by a flag, we prefer keeping
9898
-- the Hackage page simple. Just uncomment these lines when needed.
99-
-- bytestring-strict-builder >= 0.4.5 && < 0.5,
100-
-- text-builder >= 0.6.7 && < 0.7,
99+
-- bytestring-strict-builder >=0.4.5 && <0.5,
100+
-- text-builder >=1.0 && <1.1,
101+
-- text-builder-dev >=0.4 && <0.5,
101102
tasty,
102103
tasty-bench >=0.4 && <0.5

0 commit comments

Comments
 (0)