text-format 0.3.0.2 → 0.3.0.3
raw patch · 4 files changed
+18/−6 lines, 4 files
Files
- Data/Text/Format.hs +5/−5
- benchmarks/Benchmarks.hs +7/−0
- benchmarks/Simple.hs +5/−0
- text-format.cabal +1/−1
Data/Text/Format.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings, RelaxedPolyRec #-} -- | -- Module : Data.Text.Format@@ -59,16 +59,16 @@ -- | Render a format string and arguments to a 'Builder'. build :: Params ps => Format -> ps -> Builder-build fmt ps = zipParams fmt (crack fmt) (buildParams ps)+build fmt ps = zipParams (crack fmt) (buildParams ps) {-# INLINE build #-} -zipParams :: Format -> [Builder] -> [Builder] -> Builder-zipParams fmt xs = go xs+zipParams :: [Builder] -> [Builder] -> Builder+zipParams fragments params = go fragments params where go (f:fs) (y:ys) = f <> y <> go fs ys go [f] [] = f go _ _ = error . LT.unpack $ format "Data.Text.Format.build: {} sites, but {} parameters"- (ST.count "{}" (fromFormat fmt), length xs)+ (length fragments - 1, length params) crack :: Format -> [Builder] crack = map fromText . ST.splitOn "{}" . fromFormat
benchmarks/Benchmarks.hs view
@@ -12,6 +12,10 @@ printf2 :: (P.PrintfArg a, P.PrintfArg b) => String -> (a,b) -> String printf2 f (a,b) = P.printf f a b +printf3 :: (P.PrintfArg a, P.PrintfArg b, P.PrintfArg c) =>+ String -> (a,b,c) -> String+printf3 f (a,b,c) = P.printf f a b c+ main = defaultMain [ bgroup "arity" [ bench "0" $ nf (format "hi") ()@@ -30,6 +34,9 @@ , bench "format2" $ nf (format "hi mom {} {}\n") (pi::Double, "yeah"::T.Text) , bench "printf2" $ nf (printf2 "hi mom %f %s\n") (pi::Double, "yeah"::String) , bench "show2" $ nf (\(d,s) -> "hi mom " ++ show d ++ " " ++ show s ++ "\n") (pi::Double, "yeah"::String)+ , bench "format3" $ nf (format "hi mom {} {} {}\n") (pi::Double, "yeah"::T.Text, 21212121::Int)+ , bench "printf3" $ nf (printf3 "hi mom %f %s %d\n") (pi::Double, "yeah"::String, 21212121::Int)+ , bench "show3" $ nf (\(d,s,i) -> "hi mom " ++ show d ++ " " ++ show s ++ "\n") (pi::Double, "yeah"::String, 21212121::Int) ] , bgroup "types" [ bench "unit" $ nf (format "hi") ()
benchmarks/Simple.hs view
@@ -33,6 +33,10 @@ let t = T.format "hi mom {}\n" (Only i) L.putStr . encodeUtf8 $ t +bigint count = counting count $ \i x -> do+ let t = T.format "hi mom {}\n" (Only (i+100000))+ L.putStr . encodeUtf8 $ t+ double count = counting count $ \i x -> do let t = T.format "hi mom {}\n" (Only (fromIntegral i * dpi)) L.putStr . encodeUtf8 $ t@@ -85,6 +89,7 @@ ("double":_) -> double ("p6":_) -> p6 ("int":_) -> int+ ("bigint":_) -> bigint ("one":_) -> one ("two":_) -> two ("three":_) -> three
text-format.cabal view
@@ -1,5 +1,5 @@ name: text-format-version: 0.3.0.2+version: 0.3.0.3 license: BSD3 license-file: LICENSE homepage: https://github.com/mailrank/text-format