From 315b1a53e47886feb47dde9469f470f4d5b6f4d1 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Wed, 1 Apr 2015 10:25:34 -0400 Subject: [PATCH] benches/markdown: add `pandoc` engine. Signed-off-by: Alexandre Terrasa --- benchmarks/markdown/README.md | 1 + benchmarks/markdown/bench_markdown.sh | 12 ++++++++++ benchmarks/markdown/engines/Makefile | 6 ++++- benchmarks/markdown/engines/pandoc/Makefile | 27 +++++++++++++++++++++ benchmarks/markdown/engines/pandoc/pandoc.hs | 33 ++++++++++++++++++++++++++ bin/Makefile | 27 +++++++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 benchmarks/markdown/engines/pandoc/Makefile create mode 100644 benchmarks/markdown/engines/pandoc/pandoc.hs create mode 100644 bin/Makefile diff --git a/benchmarks/markdown/README.md b/benchmarks/markdown/README.md index a739cd8..29219c5 100644 --- a/benchmarks/markdown/README.md +++ b/benchmarks/markdown/README.md @@ -11,6 +11,7 @@ Benches markdown parsers. * nitmd * txtmark 0.11 (https://github.com/rjeschke/txtmark) * markdown4j 2.2 (https://code.google.com/p/markdown4j/) +* pandoc (last version installed from `cabal`) ## Benches diff --git a/benchmarks/markdown/bench_markdown.sh b/benchmarks/markdown/bench_markdown.sh index 4cb0f15..8760175 100755 --- a/benchmarks/markdown/bench_markdown.sh +++ b/benchmarks/markdown/bench_markdown.sh @@ -112,6 +112,18 @@ function bench_markdown4j() } bench_markdown4j +function bench_pandoc() +{ + name="$FUNCNAME" + skip_test "$name" && return + prepare_res $outdir/pandoc.dat "pandoc" "pandoc" + for file in $bncdir/*.md; do + name=`basename $file .md` + bench_command "$bench" "" "$engdir/pandoc/pandoc" "$file" "$s" + done +} +bench_pandoc + if test "$#" -gt 0; then plot $outdir/bench_markdown.gnu fi diff --git a/benchmarks/markdown/engines/Makefile b/benchmarks/markdown/engines/Makefile index 588e744..7301d01 100644 --- a/benchmarks/markdown/engines/Makefile +++ b/benchmarks/markdown/engines/Makefile @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -all: nitmd/nitmd txtmark/Txtmark.class markdown4j/Markdown4j.class +all: nitmd/nitmd txtmark/Txtmark.class markdown4j/Markdown4j.class pandoc/pandoc nitmd/nitmd: make -C nitmd @@ -25,7 +25,11 @@ txtmark/Txtmark.class: markdown4j/Markdown4j.class: make -C markdown4j +pandoc/pandoc: + make -C pandoc + clean: make -C nitmd clean make -C txtmark clean make -C markdown4j clean + make -C pandoc clean diff --git a/benchmarks/markdown/engines/pandoc/Makefile b/benchmarks/markdown/engines/pandoc/Makefile new file mode 100644 index 0000000..ca4a354 --- /dev/null +++ b/benchmarks/markdown/engines/pandoc/Makefile @@ -0,0 +1,27 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2015 Alexandre Terrasa +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +pandoc: + cabal install pandoc + ghc pandoc.hs -O + +test: pandoc + ./pandoc ../../benches/hello.md 5 + +clean: + rm pandoc.hi + rm pandoc.o + rm pandoc diff --git a/benchmarks/markdown/engines/pandoc/pandoc.hs b/benchmarks/markdown/engines/pandoc/pandoc.hs new file mode 100644 index 0000000..5c5db42 --- /dev/null +++ b/benchmarks/markdown/engines/pandoc/pandoc.hs @@ -0,0 +1,33 @@ +module Main where + + import System.Environment (getArgs) + import Text.Pandoc + + -- Reads a String and parses it as a Pandoc instance + readDoc :: String -> Pandoc + readDoc = readMarkdown def + + -- Writes a Pandoc instances as a String + writeDoc :: Pandoc -> String + writeDoc = writeHtmlString def + + -- Reads markdown, writes HTML and prints it in stdout + doBench :: String -> IO () + doBench fileName = do + content <- readFile fileName + let markdown = readDoc content + let html = writeDoc markdown + print html + + -- Executes `doBench` n times + loop :: Int -> String -> IO () + loop 0 _ = return () + loop n fileName = do + doBench fileName + loop (n - 1) fileName + return () + + main :: IO () + main = do + (fileName:count:_) <- getArgs + loop (read count::Int) fileName diff --git a/bin/Makefile b/bin/Makefile new file mode 100644 index 0000000..45a278a --- /dev/null +++ b/bin/Makefile @@ -0,0 +1,27 @@ +# Copyright 2013 Alexandre Terrasa . +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +all: run + +run: hello_world.jar + java -jar hello_world.jar + +hello_world.jar: nitj + NIT_DIR= ./nitj ../examples/hello_world.nit + +nitj: + NIT_DIR= ./nitg ../src/nitj.nit + +clean: + rm -rf -- hello_world.jar .nit_jcompile 2> /dev/null || true -- 1.7.9.5