]> git.immae.eu Git - github/fretlink/blazeT.git/blob - src/Benchmarks/RunHtmlBenchmarks.hs
Initial
[github/fretlink/blazeT.git] / src / Benchmarks / RunHtmlBenchmarks.hs
1 -- | This is a module which runs the 'HtmlBenchmarks' module using the different
2 -- renderers available.
3 --
4 module Benchmarks.RunHtmlBenchmarks where
5
6 import Criterion.Main
7 import qualified Data.Text.Lazy as LT
8 import Data.List
9 import qualified Data.ByteString.Lazy as LB
10
11 import qualified Text.Blaze.Renderer.Utf8 as Utf8
12 import qualified Text.Blaze.Renderer.String as String
13 import qualified Text.Blaze.Renderer.Text as Text
14
15 import Benchmarks.HtmlBenchmarks (HtmlBenchmark (..), benchmarks)
16 import qualified Benchmarks.BlazeTBenchmarks as BT (HtmlBenchmark (..), benchmarks)
17 import qualified Text.BlazeT.Renderer.Utf8 as TUtf8
18 import qualified Text.BlazeT.Renderer.String as TString
19 import qualified Text.BlazeT.Renderer.Text as TText
20
21 -- | Function to run the benchmarks using criterion
22 --
23 main :: IO ()
24 main = defaultMain $ zipWith g benchmarks BT.benchmarks
25 where
26 g x y = bgroup (hName x) $ benchHtml x ++ benchHtml2 y
27 benchHtml (HtmlBenchmark _ f x _) =
28 [ bench "Utf8" $ nf (LB.length . Utf8.renderMarkup . f) x
29 , bench "String" $ nf (String.renderMarkup . f) x
30 , bench "Text" $ nf (LT.length . Text.renderMarkup . f) x
31 ]
32 benchHtml2 (BT.HtmlBenchmark _ f x _) =
33 [ bench "BlazeT.Utf8" $ nf (LB.length . TUtf8.renderMarkup . f) x
34 , bench "BlazeT.String" $ nf (TString.renderMarkup . f) x
35 , bench "BlazeT.Text" $ nf (LT.length . TText.renderMarkup . f) x
36 ]