Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git@github.com:skogsbaer/xmlgen

  • Loading branch information...
commit 8fb060cbe6656b024de47ebe33256df6ab3ad67a 2 parents b2943eb + e5fbe6d
@skogsbaer authored
View
5 src/Text/XML/Generator.hs
@@ -54,6 +54,7 @@ import Control.Monad.Reader (Reader(..), ask, asks, runReader)
import qualified Data.Map as Map
import qualified Data.ByteString.Lazy as BSL
import Data.Monoid hiding (mconcat)
+import qualified Data.Monoid as M
import Blaze.ByteString.Builder
import qualified Blaze.ByteString.Builder as Blaze
@@ -277,7 +278,7 @@ xattrQRaw' ns' key valueBuilder = Xml $
-- | Merges a list of attributes into a single piece of XML at the attribute level.
xattrs :: [Xml Attr] -> Xml Attr
-xattrs = foldr mappend noAttrs
+xattrs = M.mconcat
-- | The empty attribute list.
noAttrs :: Xml Attr
@@ -382,7 +383,7 @@ xelemQ ns' name children = Xml $
-- | Merges a list of elements into a single piece of XML at the element level.
xelems :: [Xml Elem] -> Xml Elem
-xelems = foldr mappend noElems
+xelems = M.mconcat
-- | No elements at all.
noElems :: Xml Elem
View
26 src/Text/XML/GeneratorBenchmarks.hs
@@ -5,24 +5,18 @@ import qualified Data.Text as T
import Text.XML.Generator
-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])
+benchElems :: Int -> IO ()
+benchElems 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)) [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])
+benchAttrs :: Int -> IO ()
+benchAttrs numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc)
+ where doc = xelem "root" $ xattrs $ map (\s -> xattr ("key-" ++ s) (T.pack s)) (map (\i -> show i) [1..numberOfElems])
main =
do args <- getArgs
case args of
- "--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])
+ "--elems":s:[] -> benchElems (read s)
+ "--attrs":s:[] -> benchAttrs (read s)
+ _ -> defaultMain (concatMap (\i -> [bench (show i ++ " elems") (benchElems i),
+ bench (show i ++ " attrs") (benchAttrs i)]) [1000, 10000, 100000, 1000000])
View
2  xmlgen.cabal
@@ -45,6 +45,6 @@ Executable benchmarks
Else
Buildable: False
Hs-Source-Dirs: src
- Ghc-Options: -O2
+ Ghc-Options: -O2 -rtsopts
Ghc-Prof-Options: -auto-all -caf-all
Main-Is: Text/XML/GeneratorBenchmarks.hs
Please sign in to comment.
Something went wrong with that request. Please try again.