Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some comparisons to Lennart's printf code.

  • Loading branch information...
commit 2c8401c585778ada4628b401d78ce493e60f6eec 1 parent 62b7a71
@bos authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 benchmarks/Benchmarks.hs
View
13 benchmarks/Benchmarks.hs
@@ -4,6 +4,13 @@ import Criterion.Main
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" [
@@ -16,6 +23,12 @@ main = defaultMain [
, 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" [
Please sign in to comment.
Something went wrong with that request. Please try again.