From df0eecfc0e655c5cd78dbbd94273d0b7f9af9451 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 30 Dec 2010 15:32:34 -0800 Subject: [PATCH] More accurate benchmark for normalize. --- Benchmark.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Benchmark.hs b/Benchmark.hs index 0f3520fde..1fd787945 100644 --- a/Benchmark.hs +++ b/Benchmark.hs @@ -2,6 +2,7 @@ import Text.Pandoc import Text.Pandoc.Shared (readDataFile, normalize) import Criterion.Main import Data.List (isSuffixOf) +import Text.JSON.Generic readerBench :: Pandoc -> (String, ParserState -> String -> Pandoc) @@ -30,13 +31,15 @@ writerBench doc (name, writer) = bench (name ++ " writer") $ nf writerWrapText = True , writerLiterateHaskell = "+lhs" `isSuffixOf` name }) doc -normalizeBench :: Pandoc -> Benchmark -normalizeBench doc = bench "normalize" $ whnf normalize doc +normalizeBench :: Pandoc -> [Benchmark] +normalizeBench doc = [ bench "normalize - with" $ nf (encodeJSON . normalize) doc + , bench "normalize - without" $ nf encodeJSON doc + ] main = do inp <- readDataFile (Just ".") "README" let ps = defaultParserState{ stateSmart = True } let doc = readMarkdown ps inp let readerBs = map (readerBench doc) readers - defaultMain $ map (writerBench doc) writers ++ readerBs ++ [normalizeBench doc] + defaultMain $ map (writerBench doc) writers ++ readerBs ++ normalizeBench doc