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