Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:skogsbaer/xmlgen
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsbaer committed May 21, 2011
2 parents b2943eb + e5fbe6d commit 8fb060c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/Text/XML/Generator.hs
Expand Up @@ -54,6 +54,7 @@ import Control.Monad.Reader (Reader(..), ask, asks, runReader)
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Lazy as BSL
import Data.Monoid hiding (mconcat) import Data.Monoid hiding (mconcat)
import qualified Data.Monoid as M


import Blaze.ByteString.Builder import Blaze.ByteString.Builder
import qualified Blaze.ByteString.Builder as Blaze import qualified Blaze.ByteString.Builder as Blaze
Expand Down Expand Up @@ -277,7 +278,7 @@ xattrQRaw' ns' key valueBuilder = Xml $


-- | Merges a list of attributes into a single piece of XML at the attribute level. -- | Merges a list of attributes into a single piece of XML at the attribute level.
xattrs :: [Xml Attr] -> Xml Attr xattrs :: [Xml Attr] -> Xml Attr
xattrs = foldr mappend noAttrs xattrs = M.mconcat


-- | The empty attribute list. -- | The empty attribute list.
noAttrs :: Xml Attr noAttrs :: Xml Attr
Expand Down Expand Up @@ -382,7 +383,7 @@ xelemQ ns' name children = Xml $


-- | Merges a list of elements into a single piece of XML at the element level. -- | Merges a list of elements into a single piece of XML at the element level.
xelems :: [Xml Elem] -> Xml Elem xelems :: [Xml Elem] -> Xml Elem
xelems = foldr mappend noElems xelems = M.mconcat


-- | No elements at all. -- | No elements at all.
noElems :: Xml Elem noElems :: Xml Elem
Expand Down
26 changes: 10 additions & 16 deletions src/Text/XML/GeneratorBenchmarks.hs
Expand Up @@ -5,24 +5,18 @@ import qualified Data.Text as T


import Text.XML.Generator import Text.XML.Generator


gen1 :: Int -> IO () benchElems :: Int -> IO ()
gen1 numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc) 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) :: T.Text) [1..numberOfElems]) 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 () benchAttrs :: Int -> IO ()
gen2 numberOfElems = BSL.writeFile "/tmp/test.xml" (xrender doc) benchAttrs 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]) where doc = xelem "root" $ xattrs $ map (\s -> xattr ("key-" ++ s) (T.pack s)) (map (\i -> show i) [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 = main =
do args <- getArgs do args <- getArgs
case args of case args of
"--standalone-1":s:[] -> gen1 (read s) "--elems":s:[] -> benchElems (read s)
"--standalone-2":s:[] -> gen2 (read s) "--attrs":s:[] -> benchAttrs (read s)
"--standalone-3":s:[] -> gen3 (read s) _ -> defaultMain (concatMap (\i -> [bench (show i ++ " elems") (benchElems i),
_ -> defaultMain (concatMap (\i -> [bench ("gen1 " ++ show i) (gen1 i), bench (show i ++ " attrs") (benchAttrs i)]) [1000, 10000, 100000, 1000000])
bench ("gen2 " ++ show i) (gen2 i),
bench ("gen3 " ++ show i) (gen3 i)]) [1000, 10000, 100000, 1000000])
2 changes: 1 addition & 1 deletion xmlgen.cabal
Expand Up @@ -45,6 +45,6 @@ Executable benchmarks
Else Else
Buildable: False Buildable: False
Hs-Source-Dirs: src Hs-Source-Dirs: src
Ghc-Options: -O2 Ghc-Options: -O2 -rtsopts
Ghc-Prof-Options: -auto-all -caf-all Ghc-Prof-Options: -auto-all -caf-all
Main-Is: Text/XML/GeneratorBenchmarks.hs Main-Is: Text/XML/GeneratorBenchmarks.hs

0 comments on commit 8fb060c

Please sign in to comment.