Skip to content
Browse files

initial benchmark

  • Loading branch information...
1 parent cb28552 commit d43774e7ef46f16c619bd031f6f7c6a9708e7271 @singpolyma committed Aug 23, 2012
Showing with 117 additions and 0 deletions.
  1. +12 −0 benchmark/Makefile
  2. +11 −0 benchmark/RESULTS
  3. +14 −0 benchmark/Records.hs
  4. +33 −0 benchmark/bench1.hs
  5. +26 −0 benchmark/bench2.hs
  6. +5 −0 benchmark/sublevel.mustache
  7. +16 −0 benchmark/toplevel.mustache
View
12 benchmark/Makefile
@@ -0,0 +1,12 @@
+.PHONY: all
+
+all: bench1 bench2
+
+bench1: bench1.hs MustacheTemplates.hs Records.hs
+ ghc -Wall -fno-warn-name-shadowing $^ -o $@
+
+bench2: bench2.hs Records.hs
+ ghc -Wall -fno-warn-name-shadowing $^ -o $@
+
+MustacheTemplates.hs: toplevel.mustache sublevel.mustache
+ ../dist/build/mustache2hs/mustache2hs -m Records.hs toplevel.mustache TopLevel sublevel.mustache SubLevel > MustacheTemplates.hs
View
11 benchmark/RESULTS
@@ -0,0 +1,11 @@
+$ time ./bench1 > /dev/null
+
+real 0m0.079s
+user 0m0.072s
+sys 0m0.004s
+
+$ time ./bench2 > /dev/null
+
+real 0m1.614s
+user 0m1.352s
+sys 0m0.260s
View
14 benchmark/Records.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+module Records where
+
+import Data.Data
+
+data TopLevel = TopLevel {
+ thing :: Int,
+ subs :: [SubLevel]
+} deriving (Eq, Data, Typeable)
+
+data SubLevel = SubLevel {
+ thing2 :: Bool,
+ other :: Maybe String
+} deriving (Eq, Data, Typeable)
View
33 benchmark/bench1.hs
@@ -0,0 +1,33 @@
+module Main where
+
+import Control.Monad
+import Blaze.ByteString.Builder
+import qualified Data.ByteString as BS
+
+import Records
+import MustacheTemplates
+
+htmlEscape :: String -> String
+htmlEscape = concatMap escChar
+ where
+ escChar '&' = "&"
+ escChar '"' = """
+ escChar '<' = "&lt;"
+ escChar '>' = "&gt;"
+ escChar c = [c]
+
+main :: IO ()
+main = void $ sequence $ replicate 10000 $ toByteStringIO BS.putStr $
+ toplevel htmlEscape (TopLevel {
+ thing = 12,
+ subs = [
+ SubLevel {
+ thing2 = False,
+ other = Just "w00t!"
+ },
+ SubLevel {
+ thing2 = True,
+ other = Nothing
+ }
+ ]
+ })
View
26 benchmark/bench2.hs
@@ -0,0 +1,26 @@
+module Main where
+
+import Control.Monad
+import Blaze.ByteString.Builder
+import qualified Data.ByteString as BS
+
+import Records
+import Text.Hastache
+import Text.Hastache.Context
+
+main :: IO ()
+main = void $ sequence $ replicate 10000 $ toByteStringIO BS.putStr =<<
+ hastacheFileBuilder defaultConfig "toplevel.mustache"
+ (mkGenericContext (TopLevel {
+ thing = 12,
+ subs = [
+ SubLevel {
+ thing2 = False,
+ other = Just "w00t!"
+ },
+ SubLevel {
+ thing2 = True,
+ other = Nothing
+ }
+ ]
+ }))
View
5 benchmark/sublevel.mustache
@@ -0,0 +1,5 @@
+ other: {{other}}
+
+ {{#other}}
+ Other is truthy!
+ {{/other}}
View
16 benchmark/toplevel.mustache
@@ -0,0 +1,16 @@
+thing: {{thing}}
+
+{{#thing}}
+Thing is truthy!
+{{/thing}}
+
+{{#subs}}
+sub
+ thing2: {{thing2}}
+
+ {{^thing2}}
+ Thing2 is falsey!
+ {{/thing2}}
+
+ {{> sublevel.mustache}}
+{{/subs}}

0 comments on commit d43774e

Please sign in to comment.
Something went wrong with that request. Please try again.