Commits

Bryan O'Sullivan committed 9444eb0

Add some comparisons to Lennart's printf code.

  • Participants
  • Parent commits 0ec3584

Comments (0)

Files changed (1)

benchmarks/Benchmarks.hs

 import Data.Text.Format
 import qualified Data.Text as T
 import qualified Data.Text.Lazy as L
+import qualified Text.Printf as P
+
+printf1 :: (P.PrintfArg a) => String -> a -> String
+printf1 f a = P.printf f a
+
+printf2 :: (P.PrintfArg a, P.PrintfArg b) => String -> (a,b) -> String
+printf2 f (a,b) = P.printf f a b
 
 main = defaultMain [
          bgroup "arity" [
          , bench "4" $ nf (format "hi {}, {} - how are {} keeping {}")
                        (T.pack "mom", T.pack "hey", T.pack "you", T.pack "now")
          ]
+       , bgroup "comparison" [
+           bench "format1" $ nf (format "hi mom {}\n") (Only (pi::Double))
+         , bench "printf1" $ nf (printf1 "hi mom %f\n") (pi::Double)
+         , 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)
+         ]
        , bgroup "types" [
            bench "unit" $ nf (format "hi") ()
          , bgroup "int" [