Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

minor improvements to benchmarks

  • Loading branch information...
commit face054b1df85b831891b1bdd6494aad2a3848d2 1 parent 2a906d5
swehr authored
Showing with 11 additions and 17 deletions.
  1. +10 −16 src/Text/XML/GeneratorBenchmarks.hs
  2. +1 −1  xmlgen.cabal
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
@@ -46,6 +46,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.