From: Jean Privat Date: Sat, 27 Jul 2013 01:13:57 +0000 (-0400) Subject: Merge branch 'bench' X-Git-Tag: v0.6~4 X-Git-Url: http://nitlanguage.org?hp=de3ecaf4264f41436b077e627b1c941372b56fb9 Merge branch 'bench' --- diff --git a/benchmarks/bench_engines.sh b/benchmarks/bench_engines.sh index c2ee85f..df4bba2 100755 --- a/benchmarks/bench_engines.sh +++ b/benchmarks/bench_engines.sh @@ -96,6 +96,9 @@ function skip_test() else return 0 fi + if test -n "$html"; then + echo >>"$html" "

$1

" + fi echo "*" echo "* $1 *****" echo "*" @@ -113,7 +116,7 @@ function run_compiler() shift if test -n "$fast"; then run_command "$@" ../src/nitg.nit -o "nitg.$title.bin" - bench_command "nitg" "nitg --global ../src/test_parser.nit" "./nitg.$title.bin" -v --global --no-cc ../src/test_parser.nit + bench_command "nitg-g" "nitg --global ../src/test_parser.nit" "./nitg.$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/shoot_logic.nit -o "shoot.$title.bin" @@ -122,7 +125,7 @@ function run_compiler() bench_command "bintrees" "bench_bintree_gen 16" "./bintrees.$title.bin" 16 else run_command "$@" ../src/nitg.nit -o "nitg.$title.bin" - bench_command "nitg" "nitg --global --no-cc ../src/nitmetrics.nit" "./nitg.$title.bin" -v --global --no-cc ../src/nitmetrics.nit + bench_command "nitg-g" "nitg --global --no-cc ../src/nitmetrics.nit" "./nitg.$title.bin" -v --global --no-cc ../src/nitmetrics.nit bench_command "nitg-s" "nitg --separate ../src/nitg.nit" "./nitg.$title.bin" -v --no-cc --separate ../src/nitg.nit run_command "$@" ../src/nit.nit -o "nit.$title.bin" bench_command "nit" "nit ../src/test_parser.nit ../src/rapid_type_analysis.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/rapid_type_analysis.nit @@ -130,8 +133,10 @@ function run_compiler() bench_command "shoot" "shoot_logic 30" "./shoot.$title.bin" 30 run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin" bench_command "bintrees" "bench_bintree_gen 18" "./bintrees.$title.bin" 18 - run_command "$@" "$pep8analysis/src/pep8analysis.nit" -I "$pep8analysis/lib" -o "pep8a.$title.bin" - bench_command "pep8analisis" "bench_bintree_gen 18" "./pep8a.$title.bin" "$pep8analysis/tests/privat/"*.pep + if test -f "$pep8analysis/src/pep8analysis.nit"; then + run_command "$@" "$pep8analysis/src/pep8analysis.nit" -I "$pep8analysis/lib" -o "pep8a.$title.bin" + bench_command "pep8analisis" "bench_bintree_gen 18" "./pep8a.$title.bin" "$pep8analysis/tests/privat/"*.pep + fi fi } @@ -144,6 +149,7 @@ 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" } @@ -155,6 +161,7 @@ while [ "$stop" = false ]; do -n) count="$2"; shift; shift;; --dry) dry_run=true; shift;; --fast) fast=true; shift;; + --html) html="index.html"; echo >"$html" ""; shift;; *) stop=true esac done @@ -206,12 +213,18 @@ function bench_steps() bench_command "generate c" "" ../src/nitc_3 --global --no-cc ../src/nitg.nit bench_command "full" "" ../src/nitc_3 -O --global ../src/nitg.nit -o "nitg_nitc-g.bin" - prepare_res "$name-nitg.dat" "nitg" "Various steps of nitg --global" + 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 @@ -223,29 +236,31 @@ function bench_steps() bench_steps # $#: options to compare -function bench_nitg_options() +function bench_nitg-g_options() { tag=$1 shift name="$FUNCNAME-$tag" skip_test "$name" && return - prepare_res "$name.dat" "no options" "nitg without options" - run_compiler "nitg" ./nitg --global - - if test -n "$2"; then - prepare_res "$name-all.dat" "all" "nitg with all options $@" - run_compiler "nitg-$tag" ./nitg --global $@ + prepare_res "$name.dat" "no options" "nitg-g without options" + run_compiler "nitg-g" ./nitg --global + + if test "$1" = NOALL; then + shift + elif test -n "$2"; then + prepare_res "$name-all.dat" "all" "nitg-g with all options $@" + run_compiler "nitg-g-$tag" ./nitg --global $@ fi for opt in "$@"; do - prepare_res "$name$opt.dat" "$opt" "nitg with option $opt" - run_compiler "nitg$opt" ./nitg --global $opt + prepare_res "$name$opt.dat" "$opt" "nitg-g with option $opt" + run_compiler "nitg-g$opt" ./nitg --global $opt done plot "$name.gnu" } -bench_nitg_options "hardening" --hardening -bench_nitg_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other +bench_nitg-g_options "hardening" --hardening +bench_nitg-g_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other function bench_nitg-s_options() { @@ -256,7 +271,9 @@ function bench_nitg-s_options() prepare_res "$name.dat" "no options" "nitg-s without options" run_compiler "nitg-s" ./nitg --separate - if test -n "$2"; then + 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 $@ fi @@ -268,10 +285,10 @@ function bench_nitg-s_options() plot "$name.gnu" } -bench_nitg-s_options "slower" --hardening --no-inline-intern --generic-resolution-tree --no-union-attribute --no-shortcut-equal --no-shortcut-range +bench_nitg-s_options "slower" --hardening --no-inline-intern --no-union-attribute --no-shortcut-equal --no-shortcut-range bench_nitg-s_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other bench_nitg-s_options "faster" --inline-coloring-numbers -bench_nitg-s_options "typing" --bm-typing --phand-typing +bench_nitg-s_options "typing" NOALL --bm-typing --phand-typing function bench_nitg-e_options() { @@ -282,7 +299,9 @@ function bench_nitg-e_options() prepare_res "$name.dat" "no options" "nitg-e without options" run_compiler "nitg-e" ./nitg --erasure - if test -n "$2"; then + 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 @@ -297,7 +316,7 @@ function bench_nitg-e_options() 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-initialization --no-check-assert --no-check-autocast --no-check-other --no-check-erasure-cast bench_nitg-e_options "faster" --inline-coloring-numbers -bench_nitg-e_options "typing" --bm-typing --phand-typing +bench_nitg-e_options "typing" NOALL --bm-typing # --phand-typing function bench_nitc_gc() { @@ -334,8 +353,8 @@ function bench_engines() run_compiler "nitc" ../src/nitc_3 -O prepare_res "$name-nitc-g.dat" "nitc-g" "nitc with --global" run_compiler "nitc-g" ../src/nitc_3 -O --global - prepare_res "$name-nitg.dat" "nitg" "nitg with --global" - run_compiler "nitg" ./nitg --global + 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" @@ -355,7 +374,7 @@ function bench_nitc_vc_nitg-e() prepare_res "$name-nitc-bohem.dat" "nitc-boehm" "nitc with boehm" NIT_GC_OPTION="boehm" run_compiler "nitc" ../src/nitc_3 -O prepare_res "$name-nitg-e-nockeck-malloc.dat" "nitg-e-nc-malloc" "nitg with --erasure --no-check-autocast --no-check-erasure-cast and malloc" - run_compiler "nitg-e-nc-malloc" ./nitg --erasure --no-check-autocast --no-check-erasure-cast --make-flags "CFLAGS=\"-O2 -DNOBOEHM\"" + NIT_GC_OPTION="malloc" run_compiler "nitg-e-nc-malloc" ./nitg --erasure --no-check-autocast --no-check-erasure-cast prepare_res "$name-nitg-e-nockeck.dat" "nitg-e-nc" "nitg with --erasure --no-check-autocast --no-check-erasure-cast" run_compiler "nitg-e-nc" ./nitg --erasure --no-check-autocast --no-check-erasure-cast prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure" @@ -369,9 +388,7 @@ function bench_nitg-e_gc() name="$FUNCNAME" skip_test "$name" && return prepare_res "$name-nitg-e-malloc.dat" "nitg-e-malloc" "nitg with --erasure and malloc" - run_compiler "nitg-e-malloc" ./nitg --erasure --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" - prepare_res "$name-nitg-e-noatomic.dat" "nitg-e-noatomic" "nitg with --erasure and no atomic" - run_compiler "nitg-e-noatomic" ./nitg --erasure --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM_ATOMIC\"" + 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 plot "$name.gnu" @@ -416,10 +433,14 @@ function bench_compilation_time for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do bench_command `basename "$i" .nit` "" ../src/nitc_3 -O "$i" --no-cc done - prepare_res "$name-nitg.dat" "nitg" "nitg" + prepare_res "$name-nitg.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 done + prepare_res "$name-nitg-e.dat" "nitg-e" "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 + 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 @@ -428,6 +449,10 @@ function bench_compilation_time } bench_compilation_time +if test -n "$html"; then + echo >>"$html" "" +fi + if test -n "$died"; then echo "Some commands failed" exit 1 diff --git a/benchmarks/bench_plot.sh b/benchmarks/bench_plot.sh index 0c7d36b..e874308 100755 --- a/benchmarks/bench_plot.sh +++ b/benchmarks/bench_plot.sh @@ -62,11 +62,14 @@ function prepare_res() { echo echo "# [$2] $3 #" + if test -n "$html"; then + echo >>"$html" "

[$2] $3 data

" + fi res=$1 if [ "$plots" = "" ]; then - plots="plot '$1' using 4:2:3:xticlabels(5) ti '$2';" + plots="plot '$1' using 4:2:3:xticlabels(5) ti '$2'" else - plots="$plots replot '$1' using 4:2:3 ti '$2';" + plots="$plots, '$1' using 4:2:3 ti '$2'" fi if [ "$dry_run" = "true" ]; then return; fi echo "# [$2] $3 ; count=$count" > "$res" @@ -91,9 +94,19 @@ set title "$1 ; avg. on $count-1 runs" set ylabel "time (s)" $plots END +plots= + +if test -n "$html"; then + echo "# gnuplot $1" + bn=`basename "$1" .gnu` + gnuplot -e "set term png; set output \"$bn.png\"" "$1" + echo gnuplot -e "set term png; set output \"$bn.png\"" "$1" + + echo >>"$html" "" +else echo "# gnuplot -p $1" gnuplot -p "$1" - plots= +fi } ## GLOBAL VARIABLES ## @@ -104,3 +117,5 @@ res= # The current stuff to plot (set by prepare_res, used by plot) plots= +# The name of the html file if output is set to html +html= diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index 8fe53e5..9b4be94 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -102,6 +102,7 @@ redef class ModelBuilder # A single C file regroups many compiled rumtime functions # Note that we do not try to be clever an a small change in a Nit source file may change the content of all the generated .c files var time0 = get_time + self.toolcontext.info("*** WRITING C ***", 1) ".nit_compile".mkdir @@ -181,14 +182,14 @@ redef class ModelBuilder #p = "..".join_path(p) cc_includes += " -I \"" + p + "\"" end - makefile.write("CC = ccache cc\nCFLAGS = -g -O2{cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc\n\n") + makefile.write("CC = ccache cc\nCFLAGS = -g -O2\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc\n\n") makefile.write("all: {outname}\n\n") var ofiles = new Array[String] # Compile each generated file for f in cfiles do var o = f.strip_extension(".c") + ".o" - makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) -D NONITCNI -c -o {o} {f}\n\n") + makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) $(CINCL) -D NONITCNI -c -o {o} {f}\n\n") ofiles.add(o) end @@ -212,7 +213,7 @@ redef class ModelBuilder self.toolcontext.info("Generated makefile: {makename}", 2) var time1 = get_time - self.toolcontext.info("*** END COMPILING TO C: {time1-time0} ***", 2) + self.toolcontext.info("*** END WRITING C: {time1-time0} ***", 2) # Execute the Makefile diff --git a/src/global_compiler.nit b/src/global_compiler.nit index 7b3c944..cd2eaa2 100644 --- a/src/global_compiler.nit +++ b/src/global_compiler.nit @@ -33,7 +33,7 @@ redef class ModelBuilder fun run_global_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis) do var time0 = get_time - self.toolcontext.info("*** COMPILING TO C ***", 1) + self.toolcontext.info("*** GENERATING C ***", 1) var compiler = new GlobalCompiler(mainmodule, self, runtime_type_analysis) compiler.compile_header @@ -68,7 +68,7 @@ redef class ModelBuilder compiler.display_stats var time1 = get_time - self.toolcontext.info("*** END VISITING: {time1-time0} ***", 2) + self.toolcontext.info("*** END GENERATING C: {time1-time0} ***", 2) write_and_make(compiler) end end diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index fd13faa..aee1ea3 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -72,6 +72,11 @@ class ModelBuilder nmodules.add(mmodule2nmodule[mm]) end toolcontext.run_phases(nmodules) + + if toolcontext.opt_only_metamodel.value then + self.toolcontext.info("*** ONLY METAMODEL", 1) + exit(0) + end end # Instantiate a modelbuilder for a model and a toolcontext @@ -123,6 +128,12 @@ class ModelBuilder self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2) self.toolcontext.check_errors + + if toolcontext.opt_only_parse.value then + self.toolcontext.info("*** ONLY PARSE...", 1) + exit(0) + end + return mmodules end diff --git a/src/nit.nit b/src/nit.nit index a658d4d..e3d6f6d 100644 --- a/src/nit.nit +++ b/src/nit.nit @@ -47,8 +47,6 @@ var progname = arguments.first var mmodules = modelbuilder.parse([progname]) modelbuilder.run_phases -if toolcontext.opt_only_metamodel.value then exit(0) - # Here we launch the interpreter on the main module assert mmodules.length == 1 var mainmodule = mmodules.first diff --git a/src/nitg.nit b/src/nitg.nit index 4ebec61..58bf0f1 100644 --- a/src/nitg.nit +++ b/src/nitg.nit @@ -53,11 +53,10 @@ var progname = arguments.first # Here we load an process all modules passed on the command line var mmodules = modelbuilder.parse([progname]) + if mmodules.is_empty then return modelbuilder.run_phases -if toolcontext.opt_only_metamodel.value then exit(0) - # Here we launch the interpreter on the main module assert mmodules.length == 1 var mainmodule = mmodules.first diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index bb368ee..e383656 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -47,6 +47,9 @@ import auto_super_init redef class ModelBuilder fun do_rapid_type_analysis(mainmodule: MModule): RapidTypeAnalysis do + var time0 = get_time + self.toolcontext.info("*** RAPID TYPE ANALYSIS ***", 1) + var model = self.model var analysis = new RapidTypeAnalysis(self, mainmodule) var nmodule = self.nmodules.first @@ -62,6 +65,10 @@ redef class ModelBuilder analysis.add_monomorphic_send(maintype, mainprop) end analysis.run_analysis + + var time1 = get_time + self.toolcontext.info("*** END RAPID TYPE ANALYSIS: {time1-time0} ***", 2) + return analysis end end diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index 2a72e79..a2e5128 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -59,12 +59,13 @@ redef class ModelBuilder fun run_separate_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis) do var time0 = get_time - self.toolcontext.info("*** COMPILING TO C ***", 1) + self.toolcontext.info("*** GENERATING C ***", 1) var compiler = new SeparateCompiler(mainmodule, self, runtime_type_analysis) compiler.compile_header # compile class structures + self.toolcontext.info("Property coloring", 2) compiler.new_file("{mainmodule.name}.classes") compiler.do_property_coloring for m in mainmodule.in_importation.greaters do @@ -79,11 +80,13 @@ redef class ModelBuilder # compile methods for m in mainmodule.in_importation.greaters do + self.toolcontext.info("Generate C for module {m}", 2) compiler.new_file("{m.name}.sep") compiler.compile_module_to_c(m) end # compile live & cast type structures + self.toolcontext.info("Type coloring", 2) compiler.new_file("{mainmodule.name}.types") var mtypes = compiler.do_type_coloring for t in mtypes do @@ -92,6 +95,8 @@ redef class ModelBuilder compiler.display_stats + var time1 = get_time + self.toolcontext.info("*** END GENERATING C: {time1-time0} ***", 2) write_and_make(compiler) end end diff --git a/src/separate_erasure_compiler.nit b/src/separate_erasure_compiler.nit index d8bb170..2b3d304 100644 --- a/src/separate_erasure_compiler.nit +++ b/src/separate_erasure_compiler.nit @@ -35,12 +35,13 @@ redef class ModelBuilder fun run_separate_erasure_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis) do var time0 = get_time - self.toolcontext.info("*** COMPILING TO C ***", 1) + self.toolcontext.info("*** GENERATING C ***", 1) var compiler = new SeparateErasureCompiler(mainmodule, self, runtime_type_analysis) compiler.compile_header # compile class structures + self.toolcontext.info("Property coloring", 2) compiler.new_file("{mainmodule.name}.tables") compiler.do_property_coloring for m in mainmodule.in_importation.greaters do @@ -56,12 +57,15 @@ redef class ModelBuilder # compile methods for m in mainmodule.in_importation.greaters do + self.toolcontext.info("Generate C for module {m}", 2) compiler.new_file("{m.name}.sep") compiler.compile_module_to_c(m) end compiler.display_stats + var time1 = get_time + self.toolcontext.info("*** END GENERATING C: {time1-time0} ***", 2) write_and_make(compiler) end end