File: bench.hs

package info (click to toggle)
haskell-pandoc-types 1.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 248 kB
  • sloc: haskell: 2,293; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,267 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
35
36
37
38
39
{-# LANGUAGE OverloadedStrings #-}

import Criterion.Main (bench, defaultMain, nf)
import Text.Pandoc.Walk (walk)
import Text.Pandoc.Builder
import qualified Data.Text as T

main :: IO ()
main =
  defaultMain [
      bench "simple walk" $ nf (walk prependZeroWidthSpace) mydoc
    , bench "walk concatMap" $ nf (walk $ concatMap prependZeroWidthSpace') mydoc
    , bench "walk lists" $ nf (walk prependZeroWidthSpace'') mydoc
    ]

prependZeroWidthSpace :: Inline -> Inline
prependZeroWidthSpace (Str s) = Str (T.cons '\8203' s)
prependZeroWidthSpace x = x

prependZeroWidthSpace' :: Inline -> [Inline]
prependZeroWidthSpace' (Str s) = [Str (T.cons '\8203' s)]
prependZeroWidthSpace' x = [x]

prependZeroWidthSpace'' :: [Inline] -> [Inline]
prependZeroWidthSpace'' (Str s : xs) =
  Str (T.cons '\8203' s) : prependZeroWidthSpace'' xs
prependZeroWidthSpace'' (x : xs) =
  x : prependZeroWidthSpace'' xs
prependZeroWidthSpace'' [] = []

mydoc :: Pandoc
mydoc = setTitle "My title" $ doc $
   mconcat $ replicate 50 $
   para "This is the first paragraph" <>
   para ("And " <> emph "another" <> ".") <>
   bulletList [ para "item one" <> para "continuation"
              , plain ("item two and a " <>
                  link "/url" "go to url" "link")
              ]