benches/markdown: add `pandoc` engine.
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 1 Apr 2015 14:25:34 +0000 (10:25 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 1 Apr 2015 14:25:34 +0000 (10:25 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

benchmarks/markdown/README.md
benchmarks/markdown/bench_markdown.sh
benchmarks/markdown/engines/Makefile
benchmarks/markdown/engines/pandoc/Makefile [new file with mode: 0644]
benchmarks/markdown/engines/pandoc/pandoc.hs [new file with mode: 0644]
bin/Makefile [new file with mode: 0644]

index a739cd8..29219c5 100644 (file)
@@ -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
 
index 4cb0f15..8760175 100755 (executable)
@@ -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
index 588e744..7301d01 100644 (file)
@@ -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 (file)
index 0000000..ca4a354
--- /dev/null
@@ -0,0 +1,27 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2015 Alexandre Terrasa <alexandre@moz-code.org>
+#
+# 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 (file)
index 0000000..5c5db42
--- /dev/null
@@ -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 (file)
index 0000000..45a278a
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright 2013 Alexandre Terrasa <alexandre@moz-code.org>.
+#
+# 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