README: document nit_env.sh
[nit.git] / benchmarks / bench_engines.sh
index 75ff0aa..37b2fb9 100755 (executable)
@@ -26,14 +26,6 @@ source ./bench_plot.sh
 # Can be overrided with 'the option -n'
 count=2
 
-### HELPER FUNCTIONS ##
-
-function die()
-{
-       echo >&2 "error: $*"
-       died=1
-}
-
 # HELPER FOR NIT #
 
 # Run standards benchs on a compiler command
@@ -43,9 +35,12 @@ function run_compiler()
 {
        local title=$1
        shift
-       if test -n "$fast"; then
-               run_command "$@" ../src/nitg.nit -o "nitg.$title.bin"
-               bench_command "nitg-g" "nitg --global ../src/test_parser.nit" "./nitg.$title.bin" -v --global --no-cc ../src/test_parser.nit
+       if test "$fast" = truetrue; then
+               run_command "$@" ../examples/hello_world.nit -o "hello.$title.bin"
+               bench_command "hello" "hello_world" "./hello.$title.bin"
+       elif test -n "$fast"; then
+               run_command "$@" ../src/nitc.nit -o "nitc.$title.bin"
+               bench_command "nitc-g" "nitc --global ../src/test_parser.nit" "./nitc.$title.bin" -v --global --no-cc ../src/test_parser.nit
                run_command "$@" ../src/nit.nit -o "nit.$title.bin"
                bench_command "nit" "nit ../src/test_parser.nit ../src/location.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/location.nit
                run_command "$@" ../examples/shoot/src/shoot_logic.nit -o "shoot.$title.bin"
@@ -53,11 +48,13 @@ function run_compiler()
                run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin"
                bench_command "bintrees" "bench_bintree_gen 16" "./bintrees.$title.bin" 16
        else
-               run_command "$@" ../src/nitg.nit -o "nitg.$title.bin"
-               bench_command "nitg-g" "nitg --global --no-cc ../src/nitls.nit" "./nitg.$title.bin" -v --global --no-cc ../src/nitls.nit
-               bench_command "nitg-s" "nitg --separate ../src/nitg.nit" "./nitg.$title.bin" -v --no-cc --separate ../src/nitg.nit
+               run_command "$@" ../src/nitc.nit -o "nitc.$title.bin"
+               bench_command "nitc-g" "nitc --global --no-cc ../src/nitls.nit" "./nitc.$title.bin" -v --global --no-cc ../src/nitls.nit
+               bench_command "nitc-s" "nitc --separate ../src/nitc.nit" "./nitc.$title.bin" -v --no-cc --separate ../src/nitc.nit
                run_command "$@" ../src/nit.nit -o "nit.$title.bin"
-               bench_command "nit" "nit ../src/test_parser.nit ../src/nitls.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/nitls.nit
+               bench_command "nit-queens" "nit queens.nit 8" "./nit.$title.bin" ../lib/ai/examples/queens.nit -q 8
+               bench_command "nit-nitcc" "nit nitcc.nit calc.sablecc" "./nit.$title.bin" ../contrib/nitcc/src/nitcc.nit ../contrib/nitcc/examples/calc.sablecc
+               rm calc* 2> /dev/null # remove generated cruft
                run_command "$@" ../src/nitdoc.nit -o "nitdoc.$title.bin"
                rm -r out 2> /dev/null
                mkdir out 2> /dev/null
@@ -72,9 +69,11 @@ function run_compiler()
                bench_command "queens" "bench_queens 13" "./queens.$title.bin" 13
                run_command "$@" "../lib/ai/examples/puzzle.nit" -o "puzzle.$title.bin"
                bench_command "puzzle" "puzzle 15-hard" "./puzzle.$title.bin" kleg.mondcafjhbi
+               run_command "$@" "markdown/engines/nitmd/nitmd.nit" -o "nitmd.$title.bin"
+               bench_command "nitmd" "markdown" "./nitmd.$title.bin" markdown/benches/out/mixed.md 80
        fi
 
-       rm -r *.bin .nit_compile out
+       rm -r *.bin out 2> /dev/null
 }
 
 ## HANDLE OPTIONS ##
@@ -86,7 +85,6 @@ function usage()
        echo "  -n count: number of execution for each bar (default: $count)"
        echo "  --dry: Do not run the commands, just reuse the data and generate the graph"
        echo "  --fast: Run less and faster tests"
-       echo "  --html: Generate and HTML output"
        echo "  -h: this help"
 }
 
@@ -97,12 +95,18 @@ while [ "$stop" = false ]; do
                -h) usage; exit;;
                -n) count="$2"; shift; shift;;
                --dry) dry_run=true; shift;;
-               --fast) fast=true; shift;;
-               --html) html="index.html"; echo >"$html" "<html><head></head><body>"; shift;;
+               --fast) fast=true$fast; shift;;
+               --html) shift;; # Deprecated
                *) stop=true
        esac
 done
 
+html="index.html"
+echo >"$html" "<html><head></head><body>"
+
+xml="bench_engines.xml"
+echo "<testsuites><testsuite>" > "$xml"
+
 NOTSKIPED="$*"
 
 if test -z "$NOTSKIPED"; then
@@ -113,8 +117,13 @@ fi
 
 ## COMPILE ENGINES
 
-# get the bootstrapped nitg
-cp ../bin/nitg .
+# get the bootstrapped nitc
+cp ../bin/nitc .
+
+if test -z "$fast"; then
+       make -C markdown/benches
+       make -C ../contrib/nitcc
+fi
 
 ## EFFECTIVE BENCHS ##
 
@@ -122,207 +131,146 @@ function bench_steps()
 {
        name="$FUNCNAME"
        skip_test "$name" && return
-       prepare_res "$name-nitg.dat" "nitg-g" "Various steps of nitg --global"
-       bench_command "parse" "" ./nitg --global --only-parse ../src/nitg.nit
-       bench_command "metamodel" "" ./nitg --global --only-metamodel ../src/nitg.nit
-       bench_command "generate c" "" ./nitg --global --no-cc ../src/nitg.nit
-       bench_command "full" "" ./nitg --global ../src/nitg.nit -o "nitg_nitg.bin"
-
-       prepare_res "$name-nitg-s.dat" "nitg-s" "Various steps of nitg --separate"
-       bench_command "parse" "" ./nitg --separate --only-parse ../src/nitg.nit
-       bench_command "metamodel" "" ./nitg --separate --only-metamodel ../src/nitg.nit
-       bench_command "generate c" "" ./nitg --separate --no-cc ../src/nitg.nit
-       bench_command "full" "" ./nitg --separate ../src/nitg.nit -o "nitg_nitg-e.bin"
-
-       prepare_res "$name-nitg-e.dat" "nitg-e" "Various steps of nitg --erasure"
-       bench_command "parse" "" ./nitg --erasure --only-parse ../src/nitg.nit
-       bench_command "metamodel" "" ./nitg --erasure --only-metamodel ../src/nitg.nit
-       bench_command "generate c" "" ./nitg --erasure --no-cc ../src/nitg.nit
-       bench_command "full" "" ./nitg --erasure ../src/nitg.nit -o "nitg_nitg-e.bin"
+       prepare_res "$name-nitc.dat" "nitc-g" "Various steps of nitc --global"
+       bench_command "parse" "" ./nitc --global --only-parse ../src/nitc.nit
+       bench_command "metamodel" "" ./nitc --global --only-metamodel ../src/nitc.nit
+       bench_command "generate c" "" ./nitc --global --no-cc ../src/nitc.nit
+       bench_command "full" "" ./nitc --global ../src/nitc.nit -o "nitc_nitc.bin"
+
+       prepare_res "$name-nitc-s.dat" "nitc-s" "Various steps of nitc --separate"
+       bench_command "parse" "" ./nitc --separate --only-parse ../src/nitc.nit
+       bench_command "metamodel" "" ./nitc --separate --only-metamodel ../src/nitc.nit
+       bench_command "generate c" "" ./nitc --separate --no-cc ../src/nitc.nit
+       bench_command "full" "" ./nitc --separate ../src/nitc.nit -o "nitc_nitc-e.bin"
+
+       prepare_res "$name-nitc-e.dat" "nitc-e" "Various steps of nitc --erasure"
+       bench_command "parse" "" ./nitc --erasure --only-parse ../src/nitc.nit
+       bench_command "metamodel" "" ./nitc --erasure --only-metamodel ../src/nitc.nit
+       bench_command "generate c" "" ./nitc --erasure --no-cc ../src/nitc.nit
+       bench_command "full" "" ./nitc --erasure ../src/nitc.nit -o "nitc_nitc-e.bin"
 
        plot "$name.gnu"
 }
 bench_steps
 
-# $#: options to compare
-function bench_nitg-g_options()
+# Simple script to compare various options on nitc
+#
+# usage: *name* *common* [NOALL] *options*...
+#
+# * *name*, the name of the bench
+# * *common*, options to use on each case
+# * NOALL, optional flag to avoid a last case including all additional options
+# * *options*, sequences of options, one for each case
+#
+# Example: `bench_nitc_options "foo" "-a -b" -c "-d -e"` generates 4 cases:
+#
+# * only *common*: `nitc -a -b`
+# * *common* and first *options*: `nitc -a -b -c`
+# * *common* and second *options*: `nitc -a -b -d -e`
+# * all: *common* and all *options*: `nitc -a -b -c -d -e`
+function bench_nitc_options()
 {
        tag=$1
        shift
-       name="$FUNCNAME-$tag"
+       common=$1
+       shift
+       name="$FUNCNAME-$tag$common"
+       name=${name// /}
        skip_test "$name" && return
-       prepare_res "$name.dat" "no options" "nitg-g without options"
-       run_compiler "nitg-g" ./nitg --global
+       prepare_res "$name.dat" "no options" "nitc $common without more options"
+       run_compiler "nitc-$name" ./nitc $common
 
        if test "$1" = NOALL; then
+               withall=
                shift
-       elif test -n "$2"; then
-               prepare_res "$name-all.dat" "all" "nitg-g with all options $@"
-               run_compiler "nitg-g-$tag" ./nitg --global $@
+       else
+               withall=true
        fi
 
        for opt in "$@"; do
-               ot=${opt// /+}
-               prepare_res "$name$ot.dat" "$opt" "nitg-g with option $opt"
-               run_compiler "nitg-g$ot" ./nitg --global $opt
+               ot=${opt// /}
+               prepare_res "$name$ot.dat" "$opt" "nitc with option $opt"
+               run_compiler "nitc-$name" ./nitc $common $opt
        done
 
-       plot "$name.gnu"
-}
-bench_nitg-g_options "slower" --hardening
-bench_nitg-g_options "nocheck" --no-check-covariance --no-check-attr-isset --no-check-assert --no-check-autocast --no-check-other
-
-function bench_nitg-s_options()
-{
-       tag=$1
-       shift
-       name="$FUNCNAME-$tag"
-       skip_test "$name" && return
-       prepare_res "$name.dat" "no options" "nitg-s without options"
-       run_compiler "nitg-s" ./nitg --separate
-
-       if test "$1" = NOALL; then
-               shift
-       elif test -n "$2"; then
-               prepare_res "$name-all.dat" "all" "nitg-s with all options $@"
-               run_compiler "nitg-s-$tag" ./nitg --separate $@
+       if test -n "$2" -a -n "$withall"; then
+               prepare_res "$name-all.dat" "all" "nitc with all options $@"
+               run_compiler "nitc-$name" ./nitc $common $@
        fi
 
-       for opt in "$@"; do
-               ot=${opt// /+}
-               prepare_res "$name-$ot.dat" "$opt" "nitg-s with option $opt"
-               run_compiler "nitg-s$ot" ./nitg --separate $opt
-       done
-
        plot "$name.gnu"
 }
-bench_nitg-s_options "slower" --hardening --no-inline-intern --no-union-attribute --no-shortcut-equal --no-shortcut-range "--no-gcc-directive likely" "--no-gcc-directive noreturn"
-bench_nitg-s_options "nocheck" --no-check-covariance --no-check-attr-isset --no-check-assert --no-check-autocast --no-check-other
-bench_nitg-s_options "faster" --inline-coloring-numbers --inline-some-methods --direct-call-monomorph "--inline-some-methods --direct-call-monomorph"
 
-function bench_nitg-e_options()
-{
-       tag=$1
-       shift
-       name="$FUNCNAME-$tag"
-       skip_test "$name" && return
-       prepare_res "$name.dat" "no options" "nitg-e without options"
-       run_compiler "nitg-e" ./nitg --erasure
+bench_nitc_options "slower" --global --hardening --no-shortcut-range
+bench_nitc_options "nocheck" --global --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
 
-       if test "$1" = NOALL; then
-               shift
-       elif test -n "$2"; then
-               prepare_res "$name-all.dat" "all" "nitg-e with all options $@"
-               run_compiler "nitg-e-$tag" ./nitg --erasure $@
-       fi
+bench_nitc_options "slower" --separate --hardening --no-shortcut-equal --no-union-attribute --no-shortcut-range --no-inline-intern "--no-gcc-directive likely --no-gcc-directive noreturn" "--no-tag-primitives" "--colo-dead-methods" --type-poset
+bench_nitc_options "nocheck" --separate --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
+bench_nitc_options "faster" --separate --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph "--inline-some-methods --direct-call-monomorph"
 
-       for opt in "$@"; do
-               ot=${opt// /+}
-               prepare_res "$name$ot.dat" "$opt" "nitg-e with option $opt"
-               run_compiler "nitg-e$ot" ./nitg --erasure $opt
-       done
+bench_nitc_options "slower" --erasure --hardening --no-shortcut-equal --no-union-attribute --no-shortcut-range --no-inline-intern
+bench_nitc_options "nocheck" --erasure --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert --no-check-erasure-cast --no-check-all
+bench_nitc_options "faster" --erasure --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph --rta
 
-       plot "$name.gnu"
-}
-bench_nitg-e_options "slower" --hardening --no-inline-intern --no-union-attribute --no-shortcut-equal --no-shortcut-range
-bench_nitg-e_options "nocheck" --no-check-covariance --no-check-attr-isset --no-check-assert --no-check-autocast --no-check-other --no-check-erasure-cast
-bench_nitg-e_options "faster" --inline-coloring-numbers
+bench_nitc_options "engine" "" NOALL "--separate" "--erasure" "--separate --semi-global" "--erasure --semi-global" "--erasure --semi-global --rta" "--global"
+bench_nitc_options "policy" "" NOALL "--separate" "--erasure" "--separate --no-check-covariance" "--erasure --no-check-covariance --no-check-erasure-cast"
+bench_nitc_options "nullables" "" "--no-check-attr-isset" "--no-union-attribute"
+bench_nitc_options "linkboost" "" NOALL --trampoline-call --colors-are-symbols "--colors-are-symbols --trampoline-call" "--separate --link-boost" "--separate --colors-are-symbols --guard-call" "--separate --colors-are-symbols --direct-call-monomorph0" "--substitute-monomorph"
+bench_nitc_options "monomorph" "" --direct-call-monomorph0 --direct-call-monomorph
 
-function bench_engines()
-{
-       name="$FUNCNAME"
-       skip_test "$name" && return
-       prepare_res "$name-nitg-g.dat" "nitg-g" "nitg with --global"
-       run_compiler "nitg-g" ./nitg --global
-       prepare_res "$name-nitg-s.dat" "nitg-s" "nitg with --separate"
-       run_compiler "nitg-s" ./nitg --separate
-       prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
-       run_compiler "nitg-e" ./nitg --erasure
-       plot "$name.gnu"
-}
-bench_engines
+bench_nitc_options "misc" "" --log --typing-test-metrics --invocation-metrics --isset-checks-metrics --tables-metrics --no-stacktrace --release --debug #FIXME add --sloppy
 
-function bench_nitg-e_gc()
+function bench_nitc-e_gc()
 {
        name="$FUNCNAME"
        skip_test "$name" && return
-       prepare_res "$name-nitg-e-malloc.dat" "nitg-e-malloc" "nitg with --erasure and malloc"
-       NIT_GC_OPTION="malloc" run_compiler "nitg-e-malloc" ./nitg --erasure
-       prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
-       run_compiler "nitg-e" ./nitg --erasure
+       prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
+       run_compiler "nitc-e" ./nitc --erasure
+       prepare_res "$name-nitc-e-malloc.dat" "nitc-e-malloc" "nitc with --erasure and malloc"
+       NIT_GC_OPTION="malloc" run_compiler "nitc-e-malloc" ./nitc --erasure
+       prepare_res "$name-nitc-e-large.dat" "nitc-e-large" "nitc with --erasure and large"
+       NIT_GC_OPTION="large" run_compiler "nitc-e-large" ./nitc --erasure
        plot "$name.gnu"
 }
-bench_nitg-e_gc
+bench_nitc-e_gc
 
-function bench_cc_nitg-e()
+function bench_cc_nitc-e()
 {
        name="$FUNCNAME"
        skip_test "$name" && return
        for o in "gcc0:CC=\"ccache gcc\" CFLAGS=-O0" "cl0:CC=\"ccache clang\" CFLAGS=-O0" "gccs:CC=\"ccache gcc\" CFLAGS=-Os" "cls:CC=\"ccache clang\" CFLAGS=-Os" "gcc2:CC=\"ccache gcc\" CFLAGS=-O2" "cl2:CC=\"ccache clang\" CFLAGS=-O2" "gcc3:CC=\"ccache gcc\" CFLAGS=-O3"  "cl3:CC=\"ccache clang\" CFLAGS=-O3"; do
                f=`echo "$o" | cut -f1 -d:`
                o=`echo "$o" | cut -f2 -d:`
-               prepare_res "$name-nitg-e-$f.dat" "nitg-e-$f" "nitg with --erasure --make-flags $o"
-               run_compiler "nitg-e-$f" ./nitg --erasure --make-flags "$o"
+               prepare_res "$name-nitc-e-$f.dat" "nitc-e-$f" "nitc with --erasure --make-flags $o"
+               run_compiler "nitc-e-$f" ./nitc --erasure --make-flags "$o"
        done
        plot "$name.gnu"
 }
-bench_cc_nitg-e
-
-function bench_policy()
-{
-       name="$FUNCNAME"
-       skip_test "$name" && return
-       prepare_res "$name-nitg-s.dat" "nitg-s" "nitg with --separate"
-       run_compiler "nitg-s" ./nitg --separate
-       prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
-       run_compiler "nitg-e" ./nitg --erasure
-       prepare_res "$name-nitg-su.dat" "nitg-su" "nitg with --separate --no-check-covariance"
-       run_compiler "nitg-su" ./nitg --separate --no-check-covariance
-       prepare_res "$name-nitg-eu.dat" "nitg-eu" "nitg with --erasure --no-check-covariance --no-check-erasure-cast"
-       run_compiler "nitg-eu" ./nitg --erasure --no-check-covariance --no-check-erasure-cast
-       plot "$name.gnu"
-}
-bench_policy
-
-function bench_nullables()
-{
-       name="$FUNCNAME"
-       skip_test "$name" && return
-       prepare_res "$name-nitc.dat" "nitc" "nitc no options"
-       run_compiler "nitc" ./nitg --separate
-       prepare_res "$name-nitc-ni.dat" "nitc-ni" "nitc --no-check-attr-isset"
-       run_compiler "nitc" ./nitg --separate --no-check-attr-isset
-       prepare_res "$name-nitc-nu.dat" "nitc-nu" "nitc --no-union-attribute"
-       run_compiler "nitc" ./nitg --separate --no-union-attribute
-       prepare_res "$name-nitc-nu-ni.dat" "nitc-nu-ni" "nitc --no-union-attribute --no-check-attr-isset"
-       run_compiler "nitc" ./nitg --separate --no-union-attribute --no-check-attr-isset
-       plot "$name.gnu"
-}
-bench_nullables
+bench_cc_nitc-e
 
 function bench_compilation_time
 {
        name="$FUNCNAME"
        skip_test "$name" && return
-       prepare_res "$name-nitg-g.dat" "nitg-g" "nitg --global"
-       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
-               bench_command `basename "$i" .nit` "" ./nitg --global "$i" --no-cc
+       prepare_res "$name-nitc-g.dat" "nitc-g" "nitc --global"
+       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
+               bench_command `basename "$i" .nit` "" ./nitc --global "$i" --no-cc
        done
-       prepare_res "$name-nitg-s.dat" "nitg-s" "nitg --separate"
-       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
-               bench_command `basename "$i" .nit` "" ./nitg --separate "$i" --no-cc
+       prepare_res "$name-nitc-s.dat" "nitc-s" "nitc --separate"
+       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
+               bench_command `basename "$i" .nit` "" ./nitc --separate "$i" --no-cc
        done
-       prepare_res "$name-nitg-e.dat" "nitg-e" "nitg --erasure"
-       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
-               bench_command `basename "$i" .nit` "" ./nitg --erasure "$i" --no-cc
+       prepare_res "$name-nitc-e.dat" "nitc-e" "nitc --erasure"
+       for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
+               bench_command `basename "$i" .nit` "" ./nitc --erasure "$i" --no-cc
        done
        plot "$name.gnu"
 }
 bench_compilation_time
 
-if test -n "$html"; then
-       echo >>"$html" "</body></html>"
-fi
+echo >>"$html" "</body></html>"
+
+echo >>"$xml" "</testsuite></testsuites>"
 
 if test -n "$died"; then
        echo "Some commands failed"