text-builder 0.6.9 → 0.6.10
raw patch · 5 files changed
+54/−47 lines, 5 filesdep ~text-builder-dev
Dependency ranges changed: text-builder-dev
Files
- README.md +1/−1
- bench/Main.hs +6/−6
- library/TextBuilder.hs +8/−1
- test/Main.hs +37/−37
- text-builder.cabal +2/−2
README.md view
@@ -5,7 +5,7 @@ # Performance -The benchmarks show that it's about 2 times faster than the lazy text builder supplied with the "text" package. In the years of existence of this package the collected user feedback proves that's faster in fact.+The benchmarks show that it's about 2 times faster than the lazy text builder supplied with the "text" package. In the years of existence of this package the collected user feedback proves that it's faster in fact. ``` benchmarking Left-biased mappend/1kB/TextBuilder
bench/Main.hs view
@@ -21,13 +21,13 @@ in [ bgroup "1kB" let sample = sampleBySize 100- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ], bgroup "1MB" let sample = sampleBySize 100_000- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ] ],@@ -43,13 +43,13 @@ in [ bgroup "1kB" let sample = sampleBySize 100- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ], bgroup "1MB" let sample = sampleBySize 100_000- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ] ],@@ -65,13 +65,13 @@ in [ bgroup "1kB" let sample = sampleBySize 100- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ], bgroup "1MB" let sample = sampleBySize 100_000- in [ bench "TextBuilder" (nf sample A.run),+ in [ bench "TextBuilder" (nf sample A.toText), bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText)) ] ]
library/TextBuilder.hs view
@@ -3,6 +3,7 @@ Builder, -- * Accessors+ toText, run, length, null,@@ -95,8 +96,14 @@ null = coerce Dev.null -- | Execute a builder producing a strict text+toText :: TextBuilder -> Text+toText = coerce Dev.toText++{-# DEPRECATED run "Use toText instead" #-}++-- | Alias to 'toText' run :: TextBuilder -> Text-run = coerce Dev.buildText+run = toText -- ** Output IO
test/Main.hs view
@@ -19,68 +19,68 @@ return (ByteString.pack list) in forAll gen $ \chunks -> mconcat chunks- === Text.encodeUtf8 (B.run (foldMap B.asciiByteString chunks)),+ === Text.encodeUtf8 (B.toText (foldMap B.asciiByteString chunks)), testProperty "Intercalation has the same effect as in Text" $ \separator texts -> A.intercalate separator texts- === B.run (B.intercalate (B.text separator) (fmap B.text texts)),+ === B.toText (B.intercalate (B.text separator) (fmap B.text texts)), testProperty "Packing a list of chars is isomorphic to appending a list of builders" $ \chars -> A.pack chars- === B.run (foldMap B.char chars),+ === B.toText (foldMap B.char chars), testProperty "Concatting a list of texts is isomorphic to fold-mapping with builders" $ \texts -> mconcat texts- === B.run (foldMap B.text texts),+ === B.toText (foldMap B.text texts), testProperty "Concatting a list of texts is isomorphic to concatting a list of builders" $ \texts -> mconcat texts- === B.run (mconcat (map B.text texts)),+ === B.toText (mconcat (map B.text texts)), testProperty "Concatting a list of trimmed texts is isomorphic to concatting a list of builders" $ \texts -> let trimmedTexts = fmap (A.drop 3) texts in mconcat trimmedTexts- === B.run (mconcat (map B.text trimmedTexts)),+ === B.toText (mconcat (map B.text trimmedTexts)), testProperty "Decimal" $ \(x :: Integer) ->- (fromString . show) x === (B.run (B.decimal x)),+ (fromString . show) x === (B.toText (B.decimal x)), testProperty "Hexadecimal vs std show" $ \(x :: Integer) -> x >= 0 ==>- (fromString . showHex x) "" === (B.run . B.hexadecimal) x,+ (fromString . showHex x) "" === (B.toText . B.hexadecimal) x, testCase "Separated thousands" $ do- assertEqual "" "0" (B.run (B.thousandSeparatedUnsignedDecimal @Int ',' 0))- assertEqual "" "123" (B.run (B.thousandSeparatedUnsignedDecimal @Int ',' 123))- assertEqual "" "1,234" (B.run (B.thousandSeparatedUnsignedDecimal @Int ',' 1234))- assertEqual "" "1,234,567" (B.run (B.thousandSeparatedUnsignedDecimal @Int ',' 1234567)),+ assertEqual "" "0" (B.toText (B.thousandSeparatedUnsignedDecimal @Int ',' 0))+ assertEqual "" "123" (B.toText (B.thousandSeparatedUnsignedDecimal @Int ',' 123))+ assertEqual "" "1,234" (B.toText (B.thousandSeparatedUnsignedDecimal @Int ',' 1234))+ assertEqual "" "1,234,567" (B.toText (B.thousandSeparatedUnsignedDecimal @Int ',' 1234567)), testCase "Pad from left" $ do- assertEqual "" "00" (B.run (B.padFromLeft 2 '0' ""))- assertEqual "" "00" (B.run (B.padFromLeft 2 '0' "0"))- assertEqual "" "01" (B.run (B.padFromLeft 2 '0' "1"))- assertEqual "" "12" (B.run (B.padFromLeft 2 '0' "12"))- assertEqual "" "123" (B.run (B.padFromLeft 2 '0' "123")),+ assertEqual "" "00" (B.toText (B.padFromLeft 2 '0' ""))+ assertEqual "" "00" (B.toText (B.padFromLeft 2 '0' "0"))+ assertEqual "" "01" (B.toText (B.padFromLeft 2 '0' "1"))+ assertEqual "" "12" (B.toText (B.padFromLeft 2 '0' "12"))+ assertEqual "" "123" (B.toText (B.padFromLeft 2 '0' "123")), testCase "Pad from right" $ do- assertEqual "" "00" (B.run (B.padFromRight 2 '0' ""))- assertEqual "" "00" (B.run (B.padFromRight 2 '0' "0"))- assertEqual "" "10" (B.run (B.padFromRight 2 '0' "1"))- assertEqual "" "12" (B.run (B.padFromRight 2 '0' "12"))- assertEqual "" "123" (B.run (B.padFromRight 2 '0' "123"))- assertEqual "" "1 " (B.run (B.padFromRight 3 ' ' "1")),+ assertEqual "" "00" (B.toText (B.padFromRight 2 '0' ""))+ assertEqual "" "00" (B.toText (B.padFromRight 2 '0' "0"))+ assertEqual "" "10" (B.toText (B.padFromRight 2 '0' "1"))+ assertEqual "" "12" (B.toText (B.padFromRight 2 '0' "12"))+ assertEqual "" "123" (B.toText (B.padFromRight 2 '0' "123"))+ assertEqual "" "1 " (B.toText (B.padFromRight 3 ' ' "1")), testCase "Hexadecimal"- $ assertEqual "" "1f23" (B.run (B.hexadecimal @Int 0x01f23)),+ $ assertEqual "" "1f23" (B.toText (B.hexadecimal @Int 0x01f23)), testCase "Negative Hexadecimal"- $ assertEqual "" "-1f23" (B.run (B.hexadecimal @Int (-0x01f23))),+ $ assertEqual "" "-1f23" (B.toText (B.hexadecimal @Int (-0x01f23))), testGroup "Time interval"- $ [ testCase "59s" $ assertEqual "" "00:00:00:59" $ B.run $ B.intervalInSeconds @Rational 59,- testCase "minute" $ assertEqual "" "00:00:01:00" $ B.run $ B.intervalInSeconds @Rational 60,- testCase "90s" $ assertEqual "" "00:00:01:30" $ B.run $ B.intervalInSeconds @Rational 90,- testCase "hour" $ assertEqual "" "00:01:00:00" $ B.run $ B.intervalInSeconds @Rational 3600,- testCase "day" $ assertEqual "" "01:00:00:00" $ B.run $ B.intervalInSeconds @Rational 86400+ $ [ testCase "59s" $ assertEqual "" "00:00:00:59" $ B.toText $ B.intervalInSeconds @Rational 59,+ testCase "minute" $ assertEqual "" "00:00:01:00" $ B.toText $ B.intervalInSeconds @Rational 60,+ testCase "90s" $ assertEqual "" "00:00:01:30" $ B.toText $ B.intervalInSeconds @Rational 90,+ testCase "hour" $ assertEqual "" "00:01:00:00" $ B.toText $ B.intervalInSeconds @Rational 3600,+ testCase "day" $ assertEqual "" "01:00:00:00" $ B.toText $ B.intervalInSeconds @Rational 86400 ], testCase "dataSizeInBytesInDecimal" $ do- assertEqual "" "999B" (B.run (B.dataSizeInBytesInDecimal @Int ',' 999))- assertEqual "" "1kB" (B.run (B.dataSizeInBytesInDecimal @Int ',' 1000))- assertEqual "" "1.1kB" (B.run (B.dataSizeInBytesInDecimal @Int ',' 1100))- assertEqual "" "1.1MB" (B.run (B.dataSizeInBytesInDecimal @Int ',' 1150000))- assertEqual "" "9.9MB" (B.run (B.dataSizeInBytesInDecimal @Int ',' 9990000))- assertEqual "" "10MB" (B.run (B.dataSizeInBytesInDecimal @Int ',' 10100000))- assertEqual "" "1,000YB" (B.run (B.dataSizeInBytesInDecimal @Integer ',' 1000000000000000000000000000))+ assertEqual "" "999B" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 999))+ assertEqual "" "1kB" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 1000))+ assertEqual "" "1.1kB" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 1100))+ assertEqual "" "1.1MB" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 1150000))+ assertEqual "" "9.9MB" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 9990000))+ assertEqual "" "10MB" (B.toText (B.dataSizeInBytesInDecimal @Int ',' 10100000))+ assertEqual "" "1,000YB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 1000000000000000000000000000)) ]
text-builder.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: text-builder-version: 0.6.9+version: 0.6.10 category: Text, Builders synopsis: Efficient strict text builder description:@@ -76,7 +76,7 @@ base >=4.11 && <5, bytestring >=0.10 && <0.13, text >=1.2 && <3,- text-builder-dev >=0.3.9.1 && <0.4,+ text-builder-dev >=0.3.10 && <0.4, test-suite test import: base