File: Main.hs

package info (click to toggle)
haskell-scotty 0.20.1%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: haskell: 1,786; makefile: 6
file content (52 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# language
    OverloadedStrings
  , GeneralizedNewtypeDeriving
  #-}

module Main (main) where

import Control.Monad
import Data.Functor.Identity
import Lucid.Base
import Lucid.Html5
import Web.Scotty
import Web.Scotty.Internal.Types
import qualified Control.Monad.State.Lazy as SL
import qualified Control.Monad.State.Strict as SS
import qualified Data.ByteString.Lazy as BL

import Weigh

main :: IO ()
main = do
  mainWith $ do
    setColumns [Case,Allocated,GCs,Live,Check,Max,MaxOS]
    setFormat Markdown
    io "ScottyM Strict" BL.putStr
      (SS.evalState (runS $ renderBST htmlScotty) defaultScottyState)
    io "ScottyM Lazy" BL.putStr
      (SL.evalState (runScottyLazy $ renderBST htmlScottyLazy) defaultScottyState)
    io "Identity" BL.putStr
      (runIdentity $ renderBST htmlIdentity)

htmlTest :: Monad m => HtmlT m ()
htmlTest = replicateM_ 2 $ div_ $ do
  replicateM_ 1000 $ div_ $ do
    replicateM_ 10000 $ div_ "test"

htmlIdentity :: HtmlT Identity ()
htmlIdentity = htmlTest
{-# noinline htmlIdentity #-}

htmlScotty :: HtmlT ScottyM ()
htmlScotty = htmlTest
{-# noinline htmlScotty #-}

htmlScottyLazy :: HtmlT ScottyLazy ()
htmlScottyLazy = htmlTest
{-# noinline htmlScottyLazy #-}

newtype ScottyLazy a = ScottyLazy
  { runScottyLazy:: SL.State (ScottyState IO) a }
  deriving (Functor,Applicative,Monad)