File: benchmark.hs

package info (click to toggle)
haskell-commonmark-extensions 0.2.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 368 kB
  • sloc: haskell: 2,574; makefile: 9
file content (34 lines) | stat: -rw-r--r-- 1,138 bytes parent folder | download | duplicates (2)
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
{-# LANGUAGE CPP                 #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Test.Tasty.Bench
import Data.Text (Text)
import Data.Functor.Identity  -- base >= 4.8
import Commonmark
import Commonmark.Extensions
import qualified Data.Text as T
import qualified Data.Text.IO as TIO

main :: IO ()
main = do
  sample <- T.replicate 10 <$> TIO.readFile "benchmark/sample.md"
  defaultMain
    [ benchCommonmark (smartPunctuationSpec <> defaultSyntaxSpec)
        ("commonmark +smart", sample)
    , benchCommonmark (autolinkSpec <> defaultSyntaxSpec)
        ("commonmark +autolink", sample)
    , benchCommonmark (attributesSpec <> defaultSyntaxSpec)
        ("commonmark +attributes", sample)
    , benchCommonmark (defaultSyntaxSpec <> pipeTableSpec)
        ("commonmark +pipe_table", sample)
    ]

benchCommonmark :: SyntaxSpec Identity (Html ()) (Html ())
                -> (String, Text)
                -> Benchmark
benchCommonmark spec (name, contents) =
  bench name $
    nf (either (error . show) renderHtml
        . runIdentity . parseCommonmarkWith spec . tokenize name)
    contents