Skip to content

Commit 111ce37

Browse files
authored
large-output benchmark: Compare the different layout algorithms (#141)
Note that this benchmark doesn't use `group` and therefore cannot be used to measure the impact of any changes to `group`.
1 parent b91e770 commit 111ce37

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

prettyprinter/bench/LargeOutput.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,27 @@ main = do
183183
(progLines, progWidth) = let l = TL.lines renderedProg in (length l, maximum (map TL.length l))
184184
putDoc ("Program size:" <+> pretty progLines <+> "lines, maximum width:" <+> pretty progWidth)
185185

186-
rnf prog `seq` T.putStrLn "Staring benchmark…"
186+
let renderWith :: (Doc ann -> SimpleDocStream ann) -> Program -> TL.Text
187+
renderWith f = renderLazy . f . pretty
188+
189+
let _80ColumnsLayoutOptions = defaultLayoutOptions { layoutPageWidth = AvailablePerLine 80 0.5 }
190+
unboundedLayoutOptions = defaultLayoutOptions { layoutPageWidth = Unbounded }
191+
192+
rnf prog `seq` T.putStrLn "Starting benchmark…"
193+
187194
defaultMain
188195
[ bgroup "80 characters, 50% ribbon"
189-
[ bench "prettyprinter" (nf (renderLazy . layoutPretty defaultLayoutOptions { layoutPageWidth = AvailablePerLine 80 0.5 } . pretty) prog)
196+
[ bgroup "prettyprinter"
197+
[ bench "layoutPretty" (nf (renderWith (layoutPretty _80ColumnsLayoutOptions)) prog)
198+
, bench "layoutSmart" (nf (renderWith (layoutSmart _80ColumnsLayoutOptions)) prog)
199+
, bench "layoutCompact" (nf (renderWith layoutCompact ) prog)
200+
]
190201
, bench "ansi-wl-pprint" (nf (($ "") . WL.displayS . WL.renderPretty 0.5 80 . WL.pretty) prog) ]
191202
, bgroup "Infinite/large page width"
192-
[ bench "prettyprinter" (nf (renderLazy . layoutPretty defaultLayoutOptions { layoutPageWidth = Unbounded } . pretty) prog)
203+
[ bgroup "prettyprinter"
204+
[ bench "layoutPretty" (nf (renderWith (layoutPretty unboundedLayoutOptions)) prog)
205+
, bench "layoutSmart" (nf (renderWith (layoutSmart unboundedLayoutOptions)) prog)
206+
, bench "layoutCompact" (nf (renderWith layoutCompact ) prog)
207+
]
193208
, bench "ansi-wl-pprint" (nf (($ "") . WL.displayS . WL.renderPretty 1 (fromIntegral progWidth + 10) . WL.pretty) prog) ]
194209
]

0 commit comments

Comments
 (0)