Commits

Bryan O'Sullivan committed 9444eb0

Add some comparisons to Lennart's printf code.

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" [
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.