当前位置: 首页 > 工具软件 > Yesod > 使用案例 >

yesod / yesod-core / widget-benchmark

胡曾笑
2023-12-01
main = defaultMain
    [ bench "bigTable html" $ nf bigTableHtml bigTableData
    , bench "bigTable hamlet" $ nf bigTableHamlet bigTableData
    , bench "bigTable widget" $ nf bigTableWidget bigTableData
    , bench "bigTable blaze" $ nf bigTableBlaze bigTableData
    ]
  where
    rows :: Int
    rows = 1000
 
    bigTableData :: [[Int]]
    bigTableData = replicate rows [1..10]
    {-# NOINLINE bigTableData #-}
 
bigTableHtml rows = L.length $ renderHtml [$hamlet|
<table
    $forall row <- rows
        <tr
            $forall cell <- row
                <td>#{show cell}
|]
 
bigTableHamlet rows = L.length $ renderHamlet id [$hamlet|
<table
    $forall row <- rows
        <tr
            $forall cell <- row
                <td>#{show cell}
|]
 
bigTableWidget rows = L.length $ renderHtml $ (run [$hamlet|
<table
    $forall row <- rows
        <tr
            $forall cell <- row
                <td>#{show cell}
|]) (\_ _ -> "foo")
  where
  run (GWidget w) =
    let (_, _, GWData (Body x) _ _ _ _ _ _) = runRWS w () 0
     in x
  {-
  run (GWidget w) = runIdentity $ do
    w' <- flip evalStateT 0
        $ runWriterT $ runWriterT $ runWriterT $ runWriterT
        $ runWriterT $ runWriterT $ runWriterT w
    let ((((((((),
         Body body),
         _),
         _),
         _),
         _),
         _),
         _) = w'
 
    return body
    -}
 
bigTableBlaze t = L.length $ renderHtml $ table $ mconcat $ map row t
  where
    row r = tr $ mconcat $ map (td . string . show) r

 

转载于:https://www.cnblogs.com/kelby/archive/2012/03/19/2405842.html

 类似资料: