aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-08-25 13:58:29 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-08-25 14:24:31 -0700
commit8959c44e6ae2a2f79ca55c2c173f84bf8d3abfc7 (patch)
tree830f328f5ffca88b3a8fdce1aa96ef4d33b77287 /benchmark
parentfdb7a5b79fd180c77cf72d8b0d0f75b334ed56e1 (diff)
downloadpandoc-8959c44e6ae2a2f79ca55c2c173f84bf8d3abfc7.tar.gz
Got benchmarks working with ipynb.
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/benchmark-pandoc.hs19
1 files changed, 17 insertions, 2 deletions
diff --git a/benchmark/benchmark-pandoc.hs b/benchmark/benchmark-pandoc.hs
index f9a7d08a7..2649af8b3 100644
--- a/benchmark/benchmark-pandoc.hs
+++ b/benchmark/benchmark-pandoc.hs
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
import Prelude
import Text.Pandoc
+import Text.Pandoc.MIME
import Text.Pandoc.Error (PandocError(..))
import Control.Monad.Except (throwError)
import qualified Text.Pandoc.UTF8 as UTF8
@@ -28,6 +29,7 @@ import Criterion.Types (Config(..))
import Data.List (intersect)
import Data.Maybe (mapMaybe)
import System.Environment (getArgs)
+import qualified Data.ByteString.Lazy as BL
readerBench :: Pandoc
-> String
@@ -43,21 +45,34 @@ readerBench doc name =
case (getReader name, getWriter name) of
(Right (TextReader r, rexts),
Right (TextWriter w, wexts)) -> do
+ setResourcePath ["../test"]
inp <- w def{ writerWrapText = WrapAuto
, writerExtensions = wexts } doc
return $ (r def{ readerExtensions = rexts }, inp)
_ -> throwError $ PandocSomeError
$ "could not get text reader and writer for " ++ name
+getImages :: IO [(FilePath, MimeType, BL.ByteString)]
+getImages = do
+ ll <- BL.readFile "test/lalune.jpg"
+ mv <- BL.readFile "test/movie.jpg"
+ return [("lalune.jpg", "image/jpg", ll)
+ ,("movie.jpg", "image/jpg", mv)]
+
writerBench :: Pandoc
-> String
-> Maybe Benchmark
writerBench doc name =
case res of
Right writerFun ->
- Just $ bench (name ++ " writer")
+ Just $ env getImages $ \imgs ->
+ bench (name ++ " writer")
$ nf (\d -> either (error . show) id $
- runPure (writerFun d)) doc
+ runPure (do mapM_
+ (\(fp, mt, bs) ->
+ insertMedia fp (Just mt) bs)
+ imgs
+ writerFun d)) doc
Left _ -> Nothing
where res = runPure $ do
case (getWriter name) of