Permalink
Browse files

two more benchmarks

  • Loading branch information...
1 parent 51fc287 commit 344fdc1472754689827eace2e4a2c2307ab53e19 @skogsbaer committed Jan 26, 2011
Showing with 16 additions and 5 deletions.
  1. +0 −1 src/Text/XML/Generator.hs
  2. +16 −4 src/Text/XML/GeneratorBenchmarks.hs
View
1 src/Text/XML/Generator.hs
@@ -294,7 +294,6 @@ xelems = foldr mappend noElems
noElems :: Xml Elem
noElems = xempty
--- xelemWithText :: MkElem n (Xml Elem) => n -> String -> Xml Elem
xelemWithText n t = xelem n (xtext t)
instance Monoid (Xml Elem) where
View
20 src/Text/XML/GeneratorBenchmarks.hs
@@ -5,12 +5,24 @@ import qualified Data.Text as T
import Text.XML.Generator
-gen :: Int -> IO ()
-gen numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc)
+gen1 :: Int -> IO ()
+gen1 numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc)
where doc = xelem "root" $ xelems $ map (\s -> xelem "foo" (xattr "key" s, xtext s)) (map (\i -> T.pack (show i) :: T.Text) [1..numberOfElems])
+gen2 :: Int -> IO ()
+gen2 numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc)
+ where doc = xelem "root" $ foldr (<>) xempty $ map (\s -> xelem "foo" (xattr "key" s, xtext s)) (map (\i -> T.pack (show i) :: T.Text) [1..numberOfElems])
+
+gen3 :: Int -> IO ()
+gen3 numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc)
+ where doc = xelem "root" $ xattrs $ map (\s -> xattr "key" s) (map (\i -> T.pack (show i) :: T.Text) [1..numberOfElems])
+
main =
do args <- getArgs
case args of
- "--standalone":s:[] -> gen (read s)
- _ -> defaultMain (map (\i -> bench ("gen " ++ show i) (gen i)) [1000, 10000, 100000, 1000000])
+ "--standalone-1":s:[] -> gen1 (read s)
+ "--standalone-2":s:[] -> gen2 (read s)
+ "--standalone-3":s:[] -> gen3 (read s)
+ _ -> defaultMain (concatMap (\i -> [bench ("gen1 " ++ show i) (gen1 i),
+ bench ("gen2 " ++ show i) (gen2 i),
+ bench ("gen3 " ++ show i) (gen3 i)]) [1000, 10000, 100000, 1000000])

0 comments on commit 344fdc1

Please sign in to comment.