--- /dev/null
+all:
+ ./bench_languages.sh all
+
+check:
+ ./bench_languages.sh --fast bench_meth
+++ /dev/null
-#!/usr/bin/env nit
-
-# Microbenchmak generation for multiple language
-# Just a quick an dirty Nit script file :)
-
-# This benchmark focuses on effects of the hierarchy dept
-# on the typetest performances
-
-# class Root
-# class Klass[E] super Root
-# class C1...CX super Root
-# Klass[CX] isa Klass[C1]
-
-class Klass
- var id: Int
- var supers = new Array[Klass]
- var all_supers = new HashSet[Klass]
- redef fun to_s
- do
- return "C{id}"
- end
-end
-
-class Generator
-
- var classes = new Array[Klass]
-
- var dept writable = 5
- var loops writable = 50000
- var middle writable = 0
- var dry writable = false
- var check writable = false
-
- fun genhier
- do
- var s: nullable Klass = null
- for d in [1..dept] do
- var c = new Klass(d)
-
- classes.add(c)
- c.all_supers.add(c)
- if s != null then
- c.supers.add(s)
- c.all_supers.add_all(s.all_supers)
- end
- s = c
- end
- middle = (dept + 1) / 2
- end
-
- var file: nullable FileWriter = null
- fun write(str: String)
- do
- file.write(str)
- file.write("\n")
- end
-
- fun initnit(res: Array[String]) is abstract
- fun testnit: String do return "true"
-
- fun writenit(dir: String, name: String)
- do
- dir = "{dir}/nit"
- dir.mkdir
- file = new FileWriter.open("{dir}/{name}.nit")
-
- write "class Root\n\tfun id: Int do return 0\nend"
- for c in classes do
- write "class {c}[E]"
- if c.supers.is_empty then
- write "\tsuper Root"
- else for s in c.supers do
- write "\tsuper {s}[E]"
- end
- write "\tredef fun id do return {c.id}"
- write "end"
- end
-
- write "fun test(a,b: Root, loops, start: Int)"
- write "do"
- write "var x = start"
- write "var i = 0"
- write "while i < loops do"
- write "\tvar j = 0"
- write "\twhile j < loops do"
- var test = "true"
- if not dry then test = testnit
- write "\t\tif {test} and x >= 0 then"
- if check then write "\t\tx += 1"
- write "\telse"
- write "\t\t\tx = x - 1 + i - j"
- write "\t\t\ta = b"
- write "\t\tend"
- write "\t\tj += 1"
- write "\tend"
- write "\ti += 1"
- write "end"
- write "print x"
- write "end"
-
- var ia = new Array[String]
- initnit(ia)
- write "var a: Root = {ia.first}"
- write "var b: Root = a"
- for i in ia do
- write "\t\t\tif a.id > 0 then a = {i}"
- end
- write "test(b, b, 10, -100)"
- write "test(a, a, {loops}, 0)"
-
- file.close
- end
-
- fun initjava(res: Array[String], interfaces: Bool) is abstract
- fun testjava(interfaces: Bool): String do return "true"
- fun writejava(dir: String, name: String, interfaces: Bool)
- do
- dir = "{dir}/java"
- dir.mkdir
- file = new FileWriter.open("{dir}/{name}.java")
-
- var cl = ""
- if interfaces then cl = "X"
- write "class {name} \{"
- if interfaces then
- write "static interface Root\n\t\{ int id(); \}"
- else
- write "static class Root\n\t\{ int id() \{ return 0;\} \}"
- end
- for c in classes do
- if interfaces then
- write "static interface {c}<E> "
- else
- write "static class {c}<E> "
- end
- if c.supers.is_empty then
- write "\textends Root"
- else for s in [c.supers.first] do
- write "\textends {s}<E>"
- end
- if interfaces then
- write "\{\}"
- write "static class X{c}<E> implements {c}<E>"
- end
- write "\{"
- write "\tpublic int id() \{ return {c.id}; \}"
- write "\}"
- end
-
- write "static public void main(String args[]) \{"
- var ia = new Array[String]
- initjava(ia, interfaces)
- write "Root a = {ia.first};"
- write "Root b = a;"
- for i in ia do
- write "\t\t\tif (a.id() > 0) a = {i};"
- end
- write "\ttest(b, b, 10, -100);"
- write "\ttest(a, a, {loops}, 0);"
- write "\}"
-
- write "static public void test(Root a, Root b, int loops, int start) \{"
- write "\tint x = start;"
- write "\tfor(int i = 0; i < loops; i++) \{"
- write "\t\tfor(int j = 0; j < loops; j++) \{"
- var test = "true"
- if not dry then test = testjava(interfaces)
- write "\t\t\tif({test} && x>=0) \{"
- if check then write "\t\t\t\tx = x + 1;"
- write "\t\t\t\} else \{ x = x - 1 + i - j; a = b;\}"
- #write "\t\t\t\} else \{ x = x - 1; a = b;\}"
- write "\t\t}"
- write "\t\}"
- write "\tSystem.out.println(x);"
- write "\}"
- write "\}"
- file.close
- end
-
- fun initcsharp(res: Array[String], interfaces: Bool) is abstract
- fun testcsharp(interfaces: Bool): String do return "true"
- fun writecsharp(dir: String, name: String, interfaces: Bool)
- do
- dir = "{dir}/cs"
- dir.mkdir
- file = new FileWriter.open("{dir}/{name}.cs")
-
- var cl = ""
- if interfaces then cl = "X"
- write "class {name} \{"
- if interfaces then
- write "interface Root\n\t\{ int Id(); \}"
- else
- write "class Root\n\t\{ public int Id() \{ return 0;\} \}"
- end
- for c in classes do
- if interfaces then
- write "interface {c}<out E> "
- else
- write "class {c}<E> "
- end
- if c.supers.is_empty then
- write "\t: Root"
- else for s in [c.supers.first] do
- write "\t: {s}<E>"
- end
- if interfaces then
- write "\{\}"
- write "class X{c}<E> : {c}<E>"
- end
- write "\{"
- write "\tpublic int Id() \{ return {c.id}; \}"
- write "\}"
- end
-
- write "static void Main(string[] args) \{"
- var ia = new Array[String]
- initcsharp(ia, interfaces)
- write "Root a = {ia.first};"
- write "Root b = a;"
- for i in ia do
- write "\t\t\tif (a.Id() > 0) a = {i};"
- end
- write "\tTest(b, b, 10, -100);"
- write "\tTest(a, a, {loops}, 0);"
- write "\}"
-
- write "static void Test(Root a, Root b, int loops, int start) \{"
- write "\tint x = start;"
- write "\tfor(int i = 0; i < loops; i++) \{"
- write "\t\tfor(int j = 0; j < loops; j++) \{"
- var test = "true"
- if not dry then test = testcsharp(interfaces)
- write "\t\t\tif({test} && x>=0) \{"
- if check then write "\t\t\t\tx++;"
- write "\} else \{ x = x - 1 + i - j; a = b; \};"
- write "\t\t}"
- write "\t\}"
- write "\tSystem.Console.WriteLine(x);"
- write "\}"
- write "\}"
- file.close
- end
-
- fun initscala(res: Array[String], interfaces: Bool) is abstract
- fun testscala(interfaces: Bool): String do return "true"
- fun writescala(dir: String, name: String, interfaces: Bool)
- do
- dir = "{dir}/scala"
- dir.mkdir
- file = new FileWriter.open("{dir}/{name}.scala")
-
- var cl = ""
- write "object {name} \{"
- write "class Root\n\t\{ def id: Int = 0 \}"
- for c in classes do
- if interfaces then
- write "trait {c}[+E] "
- else
- write "class {c}[+E] "
- end
- if c.supers.is_empty then
- write "\textends Root"
- else for s in [c.supers.first] do
- write "\textends {s}[E]"
- end
- if interfaces then
- write "\{\}"
- write "class X{c}[E] extends {c}[E]"
- end
- write "\{"
- write "\toverride def id: Int = {c.id}"
- write "\}"
- end
-
- write "def main(args: Array[String]) = \{"
- var ia = new Array[String]
- initscala(ia, interfaces)
- write "var a: Root = {ia.first};"
- write "var b: Root = a;"
- for i in ia do
- write "\t\t\tif (a.id > 0) a = {i};"
- end
- write "\ttest(b, b, 10, -100)"
- write "\ttest(a, a, {loops}, 0)"
- write "\}"
-
- write "def test(aa:Root, b:Root, l: Int, start: Int) = \{"
- write "\tvar a = aa"
- write "\tvar x = start"
- write "\tvar loops = l"
- write "\tvar i = 0"
- write "\twhile (i < loops) \{"
- write "\t\tvar j = 0"
- write "\t\twhile (j < loops) \{"
- var test = "true"
- if not dry then test = testscala(interfaces)
- write "\t\tif ({test} && x>=0) \{"
- if check then write "\t\t\tx += 1;"
- #write "\} else \{ x = x - 1 + i - j; a = b; \}"
- write "\} else \{ x = x - 1; a = b; \}"
- write "\t\tj += 1"
- write "\t\t\}"
- write "\ti += 1"
- write "\t\}"
- write "\t\t\tprintln(x)"
- write "\}"
- write "\}"
-
- file.close
- end
-
- fun initcpp(res: Array[String]) is abstract
- fun testcpp: String do return "true"
- fun writecpp(dir: String, name: String)
- do
- dir = "{dir}/cpp"
- dir.mkdir
- file = new FileWriter.open("{dir}/{name}.cpp")
-
- write "#include <iostream>"
- write "#include <stdlib.h>"
- write "class Root\n\t\{ public: virtual int id() \{ return 0;\} \};"
- for c in classes do
- write "template<class E>"
- write "class {c} "
- if c.supers.is_empty then
- write "\t: public virtual Root"
- else for s in [c.supers.first] do
- write "\t: public virtual {s}<E>"
- end
- write "\{"
- write "\tpublic: virtual int id() \{ return {c.id}; \}"
- write "\};"
- end
-
- write "void test(Root *a, Root *b, int loops, int start) \{"
- write "\tint x = start;"
- write "\tfor(int i = 0; i < loops; i++) \{"
- write "\t\tfor(int j = 0; j < loops; j++) \{"
- var test = "true"
- if not dry then test = testcpp
- write "\t\tif({test} && x>=0) \{"
- if check then write "\t\t\tx += 1;"
- write "\} else \{ x = x - 1 + i - j; a = b;\}"
- write "\t\t}"
- write "\t\}"
- write "\tstd::cout << x << std::endl;"
- write "\}"
-
- write "int main(int argc, char **argv) \{"
- var ia = new Array[String]
- initcpp(ia)
- write "Root *a = {ia.first};"
- write "Root *b = a;"
- for i in ia do
- write "\t\t\tif (a->id() > 0) a = {i};"
- end
- write "\ttest(b, b, 10, -100);"
- write "\ttest(a, a, {loops}, 0);"
- write "\}"
-
- file.close
- end
-
- fun inite(res: Array[String], se: Bool) is abstract
- fun teste(se: Bool): String do return "true"
- fun locale(se: Bool) do end
- fun writee(dir: String, name: String, se: Bool)
- do
- if se then
- dir = "{dir}/se/{name}"
- else
- dir = "{dir}/es/{name}"
- end
- dir.mkdir
- file = new FileWriter.open("{dir}/root.e")
-
- var istk = ""
- if se then istk = " is"
- write "class ROOT"
- write "feature id: INTEGER {istk} do Result := 0 end"
- write "end"
- file.close
-
- for c in classes do
- file = new FileWriter.open("{dir}/{c}.e")
- write "class {c}[E] "
- if c.supers.is_empty then
- write "\tinherit ROOT"
- else for s in [c.supers.first] do
- write "\tinherit {s}[E]"
- end
- write "\t\tredefine id end"
- write "feature"
- write "\tid: INTEGER {istk} do Result := {c.id} end"
- write "end"
- file.close
- end
-
- file = new FileWriter.open("{dir}/app{name}.e")
- write "class APP{name.to_upper}"
- if se then
- write "insert ARGUMENTS"
- end
- write "create make"
- write "feature"
-
- if se then
- write "\tmake{istk}"
- else
- write "\tmake(args: ARRAY[STRING]){istk}"
- end
- write "\t\tlocal"
- write "\t\t\ta: ROOT"
- write "\t\t\tb: ROOT"
- write "\t\tdo"
- var ia = new Array[String]
- inite(ia,se)
- write "{ia.first}"
- write "b := a"
- for i in ia do
- write "\t\t\tif a.id > 0 then {i} end"
- end
- write "\t\t\ttest(b, b, 10, -100)"
- write "\t\t\ttest(a, a, {loops}, 0)"
- write "\t\tend"
-
- write "\ttest(aa: ROOT; b: ROOT; l: INTEGER; start: INTEGER){istk}"
- write "\t\tlocal"
- write "\t\t\ta: ROOT"
- write "\t\t\ti: INTEGER"
- write "\t\t\tj: INTEGER"
- write "\t\t\tx: INTEGER"
- locale(se)
- write "\t\t\tloops: INTEGER"
- write "\t\tdo"
- write "\t\t\ta := aa"
- write "\t\t\tx := start"
- write "\t\t\tloops := l"
- write "\t\t\tfrom i := 0 until i>=loops loop"
- write "\t\t\t\tfrom j := 0 until j>=loops loop"
- var test = "True"
- if not dry then test = teste(se)
- write "\t\t\t\t\tif {test} and then x >= 0 then"
- if check then write "\t\t\t\t\tx := x + 1"
- write "\t\t\t\t\telse x := x - 1 + i - j; a := b end"
- write "\t\t\t\t\tj := j + 1"
- write "\t\t\t\tend"
- write "\t\t\t\ti := i + 1"
- write "\t\t\tend"
- write "\t\t\tprint(x.out)"
- write "\t\t\tprint(\"%N\")"
- write "\t\tend"
- write "end"
- file.close
- end
-
- var count = false
-
- fun genall
- do
- var g = self
- var outdir = args.first
- var name = args[1]
- var use_interfaces = true
- if args.length > 2 then g.dept = args[2].to_i
- if args.length > 3 then use_interfaces = false
-
- g.genhier
-
- g.writenit(outdir, name)
- g.writejava(outdir, name, use_interfaces)
- g.writecsharp(outdir, name, use_interfaces)
- g.writescala(outdir, name, use_interfaces)
- g.writecpp(outdir, name)
- g.writee(outdir, "{name}_se", true)
- g.writee(outdir, name, false)
- end
-end
-
-var g = new Generator
-g.genall
# TODO: cleanup and libify the helper-parts
-source ./bench_common.sh
-source ./bench_plot.sh
+source ../bench_common.sh
+source ../bench_plot.sh
## CONFIGURATION OPTIONS ##
# Can be overrided with 'the option -n'
count=2
+xml=bench_languages.xml
+html=bench_languages.html
+verbose=true
+
+echo "" > $xml
+echo "<html><body>" > $html
+
## HANDLE OPTIONS ##
function usage()
echo " -h: this help"
}
+function system_info()
+{
+ ( # use a subshell to protect the set -x
+ export LANG=C
+ set -x
+ uname -a
+ lscpu
+ git describe --always HEAD
+ ./nitc --version
+ gcc --version
+ clang --version
+ javac -version
+ java -version
+ gcj --version
+ scalac -version
+ scala -version
+ ec -version
+ pypy --version
+ )
+}
+
stop=false
while [ "$stop" = false ]; do
case "$1" in
- -v) verbose=true; shift;;
+ -v) verbose=true; system_info; shift;;
-h) usage; exit;;
-n) count="$2"; shift; shift;;
--dry) dry_run=true; shift;;
fi
## COMPILE ENGINES
-cd ../src
-test -f ./nitc_3 || ./ncall.sh -O
-cd ../benchmarks
-test -f ./nitc || ../src/nitc_3 ../src/nitc.nit -O -v
+test -f ./nitc || ../../bin/nitc ../../src/nitc.nit --semi-global -v
+
+today=`date +%Y-%m-%d_%H-%M-%S`
+bdir="languages.${today}.out"
+rm -r "$bdir" "./languages.out" 2> /dev/null
+ln -sf "$bdir" "./languages.out"
## EFFECTIVE BENCHS ##
name="$1"
skip_test "$name" && return
rootdir=`pwd`
- basedir="./${name}.out"
-
- mkdir $basedir
+ basedir="${bdir}/${name}"
+ mkdir -p "$basedir"
t=t
- s=20
- seq="2 4 8"
+ s=50000
+ seq="3 4 8 16"
+
+ if [ "$fast" = "true" ]; then
+ s=10000
+ seq=3
+ fi
+
for b in $seq; do
- run_command ./nitc languages/$name.nit -o $basedir/$name.bin
- run_command $basedir/$name.bin $basedir "${t}_$b" "$b"
+ run_command ./nitc benches/$name.nit -o $basedir/$name.bin &&
+ run_command $basedir/$name.bin $basedir "${t}_$b" "$b" "$s"
done
prepare_res $basedir/$name-g++.dat "g++" "g++"
cppdir="${basedir}/cpp"
- for b in $seq; do
- run_command g++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.g++.bin"
+ test -d $cppdir && for b in $seq; do
+ run_command g++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.g++.bin" &&
bench_command "$b" "" "${cppdir}/${t}_$b.g++.bin" $s
done
prepare_res $basedir/$name-clang++.dat "clang++" "clang++"
- for b in $seq; do
- run_command clang++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.clang++.bin"
+ test -d $cppdir && for b in $seq; do
+ run_command clang++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.clang++.bin" &&
bench_command "$b" "" "${cppdir}/${t}_$b.clang++.bin" $s
done
prepare_res $basedir/$name-java.dat "java" "java"
javadir="${basedir}/java"
- for b in $seq; do
- run_command javac "${javadir}/${t}_$b.java"
+ test -d $javadir && for b in $seq; do
+ run_command javac "${javadir}/${t}_$b.java" &&
bench_command "$b" "" java -cp "${javadir}/" "${t}_$b" $s
done
prepare_res $basedir/$name-gcj.dat "gcj" "gcj"
- for b in $seq; do
- run_command gcj --main=${t}_$b -O2 "${javadir}/${t}_$b.java" -o "${javadir}/${t}_$b.gcj.bin"
+ test -d $javadir && for b in $seq; do
+ run_command gcj --main=${t}_$b -O2 "${javadir}/${t}_$b.java" -o "${javadir}/${t}_$b.gcj.bin" &&
bench_command "$b" "" "${javadir}/${t}_$b.gcj.bin" $s
done
prepare_res $basedir/$name-scala.dat "scala" "scala"
scaladir="${basedir}/scala"
- for b in $seq; do
- run_command scalac "${scaladir}/${t}_$b.scala" -d "${scaladir}"
+ test -d $scaladir && for b in $seq; do
+ run_command scalac "${scaladir}/${t}_$b.scala" -d "${scaladir}" &&
bench_command "$b" "" scala -cp "${scaladir}/" "${t}_$b" $s
done
prepare_res $basedir/$name-cs.dat "c#" "c#"
csdir="${basedir}/cs"
- for b in $seq; do
- run_command gmcs "$csdir/${t}_$b.cs"
+ test -d $csdir && for b in $seq; do
+ run_command mcs "$csdir/${t}_$b.cs" &&
bench_command "$b" "" mono "$csdir/${t}_$b.exe" $s
done
prepare_res $basedir/$name-es.dat "es" "es"
esdir="${basedir}/es"
- for b in $seq; do
- cd $esdir
- run_command ec -clean -finalize ${t}_$b/app${t}_$b.e
- chmod +x app${t}_$b
- mv app${t}_$b ${t}_$b.es.bin
- cd $rootdir
+ test -d $esdir && for b in $seq; do
+ run_command ec -clean -finalize "$esdir/${t}_$b/app${t}_$b.e" &&
+ chmod +x "app${t}_$b" &&
+ mv "app${t}_$b" "$esdir/${t}_$b.es.bin" &&
bench_command "$b" "" "$esdir/${t}_$b.es.bin" $s
done
+<<XXX
+ # SmartEiffel is so old...
prepare_res $basedir/$name-se.dat "se" "se"
sedir="${basedir}/se"
- for b in $seq; do
+ test -d $sedir && for b in $seq; do
cd $sedir
run_command se compile -no_check app${t}_${b}_se.e -loadpath ${t}_${b}_se -o ${t}_$b.se.bin
cd $rootdir
bench_command "$b" "" "$sedir/${t}_$b.se.bin" $s
done
+XXX
+
+ prepare_res $basedir/$name-python.dat "python" "python"
+ pythondir="${basedir}/python"
+ test -d $pythondir && for b in $seq; do
+ bench_command "$b" "" "pypy" "$pythondir/${t}_$b.py" $s
+ done
nitdir="${basedir}/nit"
- prepare_res $nitdir/$name-nitc.dat "nitc" "nitc"
- for b in $seq; do
- run_command ./nitc $nitdir/${t}_$b.nit --global -o "$nitdir/${t}_$b.nitc.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
- bench_command "$b" "" "$nitdir/${t}_$b.nitc.bin" $s
+ prepare_res $basedir/$name-nitc-g.dat "nitc-g" "nitc-g"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --global -o "$nitdir/${t}_$b.nitc-g.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
+ bench_command "$b" "" "$nitdir/${t}_$b.nitc-g.bin" $s
done
- prepare_res $nitdir/$name-nitc-s.dat "nitc-s" "nitc-s"
- for b in $seq; do
- run_command ./nitc $nitdir/${t}_$b.nit --separate -o "$nitdir/${t}_$b.nitc-s.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
- bench_command "$b" "" "$nitdir/${t}_$b.nitc-s.bin" $s
+ prepare_res $basedir/$name-nitc-sg.dat "nitc-sg" "nitc-sg"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --semi-global -o "$nitdir/${t}_$b.nitc-sg.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
+ bench_command "$b" "" "$nitdir/${t}_$b.nitc-sg.bin" $s
done
+ prepare_res $basedir/$name-nitc-s.dat "nitc-s" "nitc-s"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --separate -o "$nitdir/${t}_$b.nitc-s.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
+ bench_command "$b" "" "$nitdir/${t}_$b.nitc-s.bin" $s
+ done
<<XXX
- prepare_res $nitdir/$name-nitc-su.dat "nitc-su" "nitc-su"
- for b in $seq; do
- run_command ./nitc $nitdir/${t}_$b.nit --separate --no-check-covariance -o "$nitdir/${t}_$b.nitc-su.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+ prepare_res $basedir/$name-nitc-su.dat "nitc-su" "nitc-su"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --separate --no-check-covariance -o "$nitdir/${t}_$b.nitc-su.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
bench_command "$b" "" "$nitdir/${t}_$b.nitc-su.bin" $s
done
- prepare_res $nitdir/$name-nitc-e.dat "nitc-e" "nitc-e"
- for b in $seq; do
- run_command ./nitc $nitdir/${t}_$b.nit --erasure -o "$nitdir/${t}_$b.nitc-e.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+ prepare_res $basedir/$name-nitc-e.dat "nitc-e" "nitc-e"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --erasure -o "$nitdir/${t}_$b.nitc-e.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
bench_command "$b" "" "$nitdir/${t}_$b.nitc-e.bin" $s
done
- prepare_res $nitdir/$name-nitc-eu.dat "nitc-eu" "nitc-eu"
- for b in $seq; do
- run_command ./nitc $nitdir/${t}_$b.nit --erasure --no-check-covariance --no-check-erasure-cast -o "$nitdir/${t}_$b.nitc-eu.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+ prepare_res $basedir/$name-nitc-eu.dat "nitc-eu" "nitc-eu"
+ test -d $nitdir && for b in $seq; do
+ run_command ./nitc $nitdir/${t}_$b.nit --erasure --no-check-covariance --no-check-erasure-cast -o "$nitdir/${t}_$b.nitc-eu.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\"" &&
bench_command "$b" "" "$nitdir/${t}_$b.nitc-eu.bin" $s
done
XXX
plot $basedir/$name.gnu
}
-for name in languages/*.nit; do
+for name in benches/*.nit; do
n=`basename $name .nit`
- bench_language $n
+ bench_language $n < /dev/null
done
+echo "<h2>System Info</h2>" >> "$html"
+system_info 2>&1 | sed -e 's/$/<br>/;s|+\( .*\)|<h3>\1</h3>|' >> "$html"
+
if test -n "$died"; then
echo "Some commands failed"
exit 1
+++ /dev/null
-#!/usr/bin/env nit
-
-import bench_base
-
-class TypeTestCovarGenerator
- super Generator
-
- redef fun initnit(res)
- do
- for c in classes do
- res.add "new {classes.first}[{c}[Root]]"
- end
-
- end
-
- redef fun testnit
- do
- return "a isa {classes.first}[{classes[middle]}[Root]]"
- end
-
- redef fun initjava(res, interfaces)
- do
-
- var tagc = ""
- if interfaces then tagc = "X"
- for c in classes do
- res.add "new {tagc}{classes.first}<{c}<Root>>()"
- end
- end
-
- redef fun testjava(interfaces)
- do
- return "a instanceof {classes.first}"
- end
-
- redef fun initcsharp(res, interfaces)
- do
- var tagc = ""
- if interfaces then tagc = "X"
- for c in classes do
- res.add "new {tagc}{classes.first}<{c}<Root>>()"
- end
- end
-
- redef fun testcsharp(interfaces)
- do
- return "a is {classes.first}<{classes[middle]}<Root>>"
- end
-
- redef fun initscala(res, interfaces)
- do
- var tagc = ""
- if interfaces then tagc = "X"
- for c in classes do
- res.add "new {tagc}{classes.first}[{c}[Root]]()"
- end
- end
-
- redef fun testscala(interfaces)
- do
- return "a.isInstanceOf[{classes.first}[{classes[middle]}[Root]]]"
- end
-
- redef fun initcpp(res)
- do
- for c in classes do
- res.add "new {classes.first}<{c}<Root>*>()"
- end
- end
-
- redef fun testcpp
- do
- write "\t\t\t{classes.first}<{classes[middle]}<Root>*> *to = dynamic_cast<{classes.first}<{classes[middle]}<Root>*>*>(a);"
- return "to != 0"
- end
-
- redef fun inite(res, se)
- do
- for c in classes do
- res.add "create \{{classes.first}[{c}[ROOT]]\} a"
- end
- end
-
- redef fun teste(se)
- do
- write "\t\t\t\t\tto ?= a"
- return "to /= Void"
- end
-
- redef fun locale(se)
- do
- write "\t\t\tto: {classes.first}[{classes[middle]}[ROOT]]"
- end
-end
-
-var g = new TypeTestCovarGenerator
-g.genall
--- /dev/null
+#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import bench_base
+
+class TypeTestDepthGenerator
+ super Generator
+
+ redef fun initnit(res)
+ do
+ for c in classes do
+ res.add "new {c}[Root]"
+ end
+ end
+
+ redef fun testnit
+ do
+ return "a._aid >= {middle}"
+ end
+
+ redef fun initjava(res, interfaces)
+ do
+
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun testjava(interfaces)
+ do
+ return "a.aid >= {middle}"
+ end
+
+ redef fun initcsharp(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun testcsharp(interfaces)
+ do
+ return "a.aid >= {middle}"
+ end
+
+ redef fun initscala(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}[Root]()"
+ end
+ end
+
+ redef fun testscala(interfaces)
+ do
+ return "a.aid >= {middle}"
+ end
+
+ redef fun initcpp(res)
+ do
+ for c in classes do
+ res.add "new {c}<Root>()"
+ end
+ end
+
+ redef fun testcpp
+ do
+ return "a->aid >= {middle}"
+ end
+
+ redef fun inite(res, se)
+ do
+ for c in classes do
+ res.add "create \{{c}[ROOT]\}"
+ end
+ end
+
+ redef fun teste(se)
+ do
+ return "a.aid >= {middle}"
+ end
+
+ redef fun initpython(res)
+ do
+ for c in classes do
+ res.add "{c}()"
+ end
+ end
+
+ redef fun testpython
+ do
+ return "a.aid >= {middle}"
+ end
+end
+
+var g = new TypeTestDepthGenerator
+g.use_interfaces = false
+g.genall
--- /dev/null
+#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+# Microbenchmak generation for multiple language
+# Just a quick an dirty Nit script file :)
+
+# This benchmark focuses on effects of the hierarchy dept
+# on the typetest performances
+
+# class Root
+# class Klass[E] super Root
+# class C1...CX super Root
+# Klass[CX] isa Klass[C1]
+
+class Klass
+ var id: Int
+ var supers = new Array[Klass]
+ var all_supers = new HashSet[Klass]
+ redef fun to_s
+ do
+ return "C{id}"
+ end
+end
+
+class Generator
+
+ var classes = new Array[Klass]
+
+ var dept = 5 is writable
+ var loops = 50000 is writable
+ var middle = 0 is writable
+ var dry = false is writable
+ var check = false is writable
+
+ # Polymorphism level
+ # This is the number of distinct dynamic types for the receiver
+ var poly = 2 is writable
+
+ # Use only interfaces (or traits) in the hierarchy
+ #
+ # If `false` then java&cs&scala will use classes, thus will break if MH is used
+ var use_interfaces = true is writable
+
+ # Add Root0, the superclass to Root that introduce common services.
+ #
+ # This add another level of un-optimization since the services are not introduced
+ # by the static type of the receiver.
+ var use_root0 = true is writable
+
+ fun genhier
+ do
+ var s: nullable Klass = null
+ for d in [1..dept] do
+ var c = new Klass(d)
+
+ classes.add(c)
+ c.all_supers.add(c)
+ if s != null then
+ c.supers.add(s)
+ c.all_supers.add_all(s.all_supers)
+ end
+ s = c
+ end
+ middle = (dept) / 2
+ end
+
+ var file: nullable FileWriter = null
+ fun write(str: String)
+ do
+ file.write(str)
+ file.write("\n")
+ end
+
+ fun initnit(res: Array[String]) do return
+ fun testnit: String do return "true"
+
+ fun writenit(dir: String, name: String)
+ do
+ var ia = new Array[String]
+ initnit(ia)
+ if ia.is_empty then
+ print "Nit disabled"
+ return
+ end
+
+ dir = "{dir}/nit"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.nit")
+
+ if use_root0 then
+ write "class Root0"
+ else
+ write "class Root"
+ end
+ write "\tfun id: Int do return 0"
+ write "\tvar aid: Int = id"
+ write "\tvar next: Root is noautoinit"
+ write "\tfun set_next(next: Root): Root do\n\t\tself.next = next\n\t\treturn next\n\tend"
+ write "end"
+ if use_root0 then
+ write "class Root\n\tsuper Root0\nend"
+ end
+ for c in classes do
+ write "class {c}[E]"
+ if c.supers.is_empty then
+ write "\tsuper Root"
+ else for s in c.supers do
+ write "\tsuper {s}[E]"
+ end
+ write "\tredef fun id do return {c.id}"
+ write "\tfun f{c.id}: Int do return {c.id}"
+ write "\tvar a{c.id}: Int = {c.id}"
+ write "end"
+ end
+
+ write "fun test(a,b: Root, loops, start: Int)"
+ write "do"
+ write "var x = start"
+ write "var i = loops"
+ write "while i > 0 do"
+ write "\tvar j = loops"
+ write "\twhile j > 0 do"
+ var test = "x >= 0"
+ if not dry then test = testnit
+ write "\t\tif {test} then"
+ write "\t\t\tvar tmp = a; a = b; b = tmp"
+ if check then write "\t\tx += 1"
+ write "\t\telse"
+ write "\t\t\tx += 1"
+ write "\t\t\ta = a.next"
+ write "\t\t\tb = b.next"
+ write "\t\tend"
+ write "\t\tj -= 1"
+ write "\tend"
+ write "\tx += 1"
+ write "\ta = a.next"
+ write "\tb = b.next"
+ write "\ti -= 1"
+ write "end"
+ write "print x"
+ write "end"
+
+ write "var b: Root = {ia.first}"
+ write "var tmp = b"
+ for i in ia do
+ write "b = b.set_next({i})"
+ end
+ write "b.next = tmp"
+ write "var a: Root = {ia.last}"
+ write "tmp = a"
+ for i in [1..poly[ do
+ write "a = a.set_next({ia[ia.length - 1 - i]})"
+ end
+ write "a.next = tmp"
+ write "test(b, b.next, 10, -100)"
+ write "test(a, a.next, {loops}, 0)"
+
+ file.close
+ end
+
+ fun initjava(res: Array[String], interfaces: Bool) do return
+ fun testjava(interfaces: Bool): String do return "true"
+ fun writejava(dir: String, name: String, interfaces: Bool)
+ do
+ var ia = new Array[String]
+ initjava(ia, interfaces)
+ if ia.is_empty then
+ print "Java disabled"
+ return
+ end
+
+ dir = "{dir}/java"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.java")
+
+ write "class {name} \{"
+ var root0 = "Root"
+ if use_root0 then root0 = "Root0"
+ if interfaces then
+ write "static interface {root0} \{ long id(); Root getNext(); Root setNext(Root next); \}"
+ write "static class XRoot implements {root0} \{"
+ else
+ write "static class {root0} \{"
+ end
+ write "\tpublic long id() \{ return 0;\}"
+ write "\tpublic long aid = id();"
+ write "\tpublic Root next;"
+ write "\tpublic Root getNext() \{ return next;\}"
+ write "\tpublic Root setNext(Root next) \{ this.next = next; return next; \}"
+ write "\}"
+
+ if use_root0 then
+ if interfaces then
+ write "static interface Root extends Root0 \{\}"
+ else
+ write "static class Root extends Root0 \{\}"
+ end
+ end
+
+ for c in classes do
+ if interfaces then
+ write "static interface {c}<E> "
+ else
+ write "static class {c}<E> "
+ end
+ if c.supers.is_empty then
+ write "\textends Root"
+ else for s in [c.supers.first] do
+ write "\textends {s}<E>"
+ end
+ if interfaces then
+ write "\{\}"
+ if c.supers.is_empty then
+ write "static class X{c}<E> extends XRoot implements {c}<E>"
+ else
+ write "static class X{c}<E> extends X{c.supers.first}<E> implements {c}<E>"
+ end
+ end
+ write "\{"
+ write "\tpublic long id() \{ return {c.id}; \}"
+ write "\tpublic long f{c.id}() \{ return {c.id}; \}"
+ write "\tpublic long a{c.id} = {c.id};"
+ write "\}"
+ end
+
+ write "static public void main(String args[]) \{"
+ write "\tRoot b = {ia.first};"
+ write "\tRoot tmp = b;"
+ for i in ia do
+ write "\tb = b.setNext({i});"
+ end
+ write "\tb.setNext(tmp);"
+ write "\tRoot a = {ia.last};"
+ write "\ttmp = a;"
+ for i in [1..poly[ do
+ write "\ta = a.setNext({ia[ia.length - 1 - i]});"
+ end
+ write "\ta.setNext(tmp);"
+ write "\ttest(b, b.getNext(), 10, -100);"
+ write "\ttest(a, a.getNext(), {loops}, 0);"
+ write "\}"
+
+ write "static public void test(Root a, Root b, long loops, long start) \{"
+ write "\tlong x = start;"
+ write "\tfor(long i = loops; i > 0; i--) \{"
+ write "\t\tfor(long j = loops; j > 0; j--) \{"
+ var test = "x>=0"
+ if not dry then test = testjava(interfaces)
+ write "\t\t\tif({test}) \{"
+ write "\t\t\t\tRoot tmp = a; a = b; b = tmp;"
+ if check then write "\t\t\t\tx = x + 1;"
+ write "\t\t\t\} else \{ x++; a = a.getNext(); b = b.getNext(); \}"
+ write "\t\t\}"
+ write "\t\tx++; a = a.getNext(); b = b.getNext();"
+ write "\t\}"
+ write "\tSystem.out.println(x);"
+ write "\}"
+ write "\}"
+ file.close
+ end
+
+ fun initcsharp(res: Array[String], interfaces: Bool) do return
+ fun testcsharp(interfaces: Bool): String do return "true"
+ fun writecsharp(dir: String, name: String, interfaces: Bool)
+ do
+ var ia = new Array[String]
+ initcsharp(ia, interfaces)
+ if ia.is_empty then
+ print "C# disabled"
+ return
+ end
+
+ dir = "{dir}/cs"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.cs")
+
+ write "class {name} \{"
+ var root0 = "Root"
+ if use_root0 then root0 = "Root0"
+ if interfaces then
+ write "interface {root0} \{ long Id(); Root GetNext(); Root SetNext(Root next); \}"
+ write "class XRoot: {root0} \{ "
+ else
+ write "class {root0}\n\t\{ "
+ end
+ write "\tvirtual public long Id() \{ return 0; \}"
+ write "\tpublic long aid;"
+ write "\tpublic Root next;"
+ write "\tvirtual public Root GetNext() \{ return next; \}"
+ write "\tvirtual public Root SetNext(Root next) \{ this.next = next; return next; \}"
+ write "\}"
+
+ if use_root0 then
+ if interfaces then
+ write "interface Root: Root0 \{\}"
+ else
+ write "class Root: Root0 \{\}"
+ end
+ end
+
+ for c in classes do
+ var cname
+ if interfaces then
+ write "interface {c}<out E> "
+ cname = "X"+c.to_s
+ else
+ write "class {c}<E> "
+ cname = c.to_s
+ end
+ if c.supers.is_empty then
+ write "\t: Root"
+ else for s in [c.supers.first] do
+ write "\t: {s}<E>"
+ end
+ if interfaces then
+ write "\{\}"
+ if c.supers.is_empty then
+ write "class X{c}<E>: XRoot, {c}<E>"
+ else
+ write "class X{c}<E>: X{c.supers.first}<E>, {c}<E>"
+ end
+ end
+ write "\{"
+ write "\toverride public long Id() \{ return {c.id}; \}"
+ write "\tvirtual public long F{c.id}() \{ return {c.id}; \}"
+ write "\tpublic long A{c.id} = {c.id};"
+ write "\tpublic {cname}() \{ aid = {c.id}; \}"
+ write "\}"
+ end
+
+ write "static void Main(string[] args) \{"
+ write "\tRoot b = {ia.first};"
+ write "\tRoot tmp = b;"
+ for i in ia do
+ write "\tb = b.SetNext({i});"
+ end
+ write "\tb.SetNext(tmp);"
+ write "\tRoot a = {ia.last};"
+ write "\ttmp = a;"
+ for i in [1..poly[ do
+ write "\ta = a.SetNext({ia[ia.length - 1 - i]});"
+ end
+ write "\ta.SetNext(tmp);"
+ write "\tTest(b, b.GetNext(), 10, -100);"
+ write "\tTest(a, a.GetNext(), {loops}, 0);"
+ write "\}"
+
+ write "static void Test(Root a, Root b, long loops, long start) \{"
+ write "\tlong x = start;"
+ write "\tfor(long i = loops; i > 0; i--) \{"
+ write "\t\tfor(long j = loops; j >0; j--) \{"
+ var test = "x>=0"
+ if not dry then test = testcsharp(interfaces)
+ write "\t\t\tif({test}) \{"
+ write "\t\t\t\tRoot tmp = a; a = b; b = tmp;"
+ if check then write "\t\t\t\tx++;"
+ write "\t\t\t\} else \{ x += 1; a = a.GetNext(); b = b.GetNext();\};"
+ write "\t\t\}"
+ write "\t\tx += 1; a = a.GetNext(); b = b.GetNext();"
+ write "\t\}"
+ write "\tSystem.Console.WriteLine(x);"
+ write "\}"
+ write "\}"
+ file.close
+ end
+
+ fun initscala(res: Array[String], interfaces: Bool) do return
+ fun testscala(interfaces: Bool): String do return "true"
+ fun writescala(dir: String, name: String, interfaces: Bool)
+ do
+ var ia = new Array[String]
+ initscala(ia, interfaces)
+ if ia.is_empty then
+ print "Scala disabled"
+ return
+ end
+
+ dir = "{dir}/scala"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.scala")
+
+ write "object {name} \{"
+ if use_root0 then
+ write "class Root0 \{"
+ else
+ write "class Root \{"
+ end
+ write "\tdef id: Long = 0; var aid: Long = id; var next: Root = null; def getNext: Root = next; def setNext(next: Root): Root = \{ this.next = next; return next; \} \}"
+
+ if use_root0 then
+ write "class Root extends Root0 \{\}"
+ end
+
+ for c in classes do
+ if interfaces then
+ write "trait {c}[+E] "
+ else
+ write "class {c}[+E] "
+ end
+ if c.supers.is_empty then
+ write "\textends Root"
+ else for s in [c.supers.first] do
+ write "\textends {s}[E]"
+ end
+ if interfaces then
+ write "\{\}"
+ if c.supers.is_empty then
+ write "class X{c}[E] extends {c}[E]"
+ else
+ write "class X{c}[E] extends X{c.supers.first}[E] with {c}[E]"
+ end
+ end
+ write "\{"
+ write "\toverride def id: Long = {c.id}"
+ write "\tdef f{c.id}: Long = {c.id}"
+ if interfaces then
+ write "\tvar a{c.id}: Long = {c.id}"
+ end
+ write "\}"
+ end
+
+ write "def main(args: Array[String]) = \{"
+ write "\tvar b: Root = {ia.first};"
+ write "\tvar tmp = b;"
+ for i in ia do
+ write "\tb = b.setNext({i});"
+ end
+ write "\tb.setNext(tmp);"
+ write "\tvar a: Root = {ia.last};"
+ write "\ttmp = a;"
+ for i in [1..poly[ do
+ write "\ta = a.setNext({ia[ia.length - 1 - i]});"
+ end
+ write "\ta.setNext(tmp);"
+ write "\ttest(b, b.getNext, 10, -100);"
+ write "\ttest(a, a.getNext, {loops}, 0);"
+ write "\}"
+
+ write "def test(aa:Root, bb:Root, l: Long, start: Long) = \{"
+ write "\tvar a = aa"
+ write "\tvar b = bb"
+ write "\tvar x = start"
+ write "\tvar loops = l"
+ write "\tvar i = loops"
+ write "\twhile (i > 0) \{"
+ write "\t\tvar j = loops"
+ write "\t\twhile (j > 0) \{"
+ var test = "x>=0"
+ if not dry then test = testscala(interfaces)
+ write "\t\t\tif ({test}) \{"
+ write "\t\t\t\tval tmp = a; a = b; b = tmp;"
+ if check then write "\t\t\t\tx += 1;"
+ write "\t\t\t\} else \{ x += 1; a = a.getNext; b = b.getNext;\}"
+ write "\t\t\tj -= 1"
+ write "\t\t\}"
+ write "\t\tx += 1; a = a.getNext; b = b.getNext;"
+ write "\t\ti -= 1"
+ write "\t\t\}"
+ write "\tprintln(x)"
+ write "\}"
+ write "\}"
+
+ file.close
+ end
+
+ fun initcpp(res: Array[String]) do return
+ fun testcpp: String do return "true"
+ fun writecpp(dir: String, name: String)
+ do
+ var ia = new Array[String]
+ initcpp(ia)
+ if ia.is_empty then
+ print "C++ diabled"
+ return
+ end
+
+ dir = "{dir}/cpp"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.cpp")
+
+ write "#include <iostream>"
+ write "#include <stdlib.h>"
+ if use_root0 then
+ write "class Root;"
+ write "class Root0"
+ else
+ write "class Root"
+ end
+ write "\t\{ public: virtual long id() \{ return 0;\} long aid; Root *next; virtual Root *setNext(Root *n) \{this->next = n; return n;\} \};"
+
+ if use_root0 then
+ write "class Root: public virtual Root0 \{\};"
+ end
+
+ for c in classes do
+ write "template<class E>"
+ write "class {c} "
+ if c.supers.is_empty then
+ write "\t: public virtual Root"
+ else for s in [c.supers.first] do
+ write "\t: public virtual {s}<E>"
+ end
+ write "\{"
+ write "\tpublic: virtual long id() \{ return {c.id}; \}"
+ write "\tvirtual long f{c.id}() \{ return {c.id}; \}"
+ write "\tlong a{c.id};"
+ write "\t{c}(): a{c.id}({c.id}) \{ this->aid = {c.id}; \}"
+ write "\};"
+ end
+
+ write "void test(Root *a, Root *b, long loops, long start) \{"
+ write "\tlong x = start;"
+ write "\tfor(long i = loops; i > 0; i--) \{"
+ write "\t\tfor(int j = loops; j > 0; j--) \{"
+ var test = "x>=0"
+ if not dry then test = testcpp
+ write "\t\t\tif({test}) \{"
+ write "\t\t\t\tRoot *tmp = a; a = b; b = tmp;"
+ if check then write "\t\t\t\tx += 1;"
+ write "\t\t\t\} else \{ x++; a = a->next; b = b->next;\}"
+ write "\t\t\}"
+ write "\t\tx++; a = a->next; b = b->next;"
+ write "\t\}"
+ write "\tstd::cout << x << std::endl;"
+ write "\}"
+
+ write "int main(int argc, char **argv) \{"
+ write "\tRoot *b = {ia.first};"
+ write "\tRoot *tmp = b;"
+ for i in ia do
+ write "\tb = b->setNext({i});"
+ end
+ write "\tb->setNext(tmp);"
+ write "\tRoot *a = {ia.last};"
+ write "\ttmp = a;"
+ for i in [1..poly[ do
+ write "\ta = a->setNext({ia[ia.length - 1 - i]});"
+ end
+ write "\ta->setNext(tmp);"
+ write "\ttest(b, b->next, 10, -100);"
+ write "\ttest(a, a->next, {loops}, 0);"
+ write "\}"
+
+ file.close
+ end
+
+ fun inite(res: Array[String], se: Bool) do return
+ fun teste(se: Bool): String do return "true"
+ fun locale(se: Bool) do end
+ fun writee(dir: String, name: String, se: Bool)
+ do
+ var ia = new Array[String]
+ inite(ia,se)
+ if ia.is_empty then
+ print "Eiffel disabled"
+ return
+ end
+
+ if se then
+ dir = "{dir}/se/{name}"
+ else
+ dir = "{dir}/es/{name}"
+ end
+ dir.mkdir
+
+ var root0
+ if use_root0 then
+ root0 = "ROOT0"
+ file = new FileWriter.open("{dir}/root0.e")
+ else
+ root0 = "ROOT"
+ file = new FileWriter.open("{dir}/root.e")
+ end
+
+ var istk = ""
+ if se then istk = " is"
+ write "class {root0}"
+ write "feature id: INTEGER_64 {istk} do Result := 0 end"
+ write "aid: INTEGER_64"
+ write "xnext: detachable ROOT"
+ write "next: ROOT do check attached xnext as n then Result := n end end"
+ write "set_next(n: ROOT): ROOT do xnext := n Result := n end"
+ write "make do aid := id end"
+ write "end"
+ file.close
+
+ if use_root0 then
+ file = new FileWriter.open("{dir}/root.e")
+ write "class ROOT inherit ROOT0 end "
+ file.close
+ end
+
+ for c in classes do
+ file = new FileWriter.open("{dir}/{c}.e")
+ write "class {c}[E] "
+ if c.supers.is_empty then
+ write "\tinherit ROOT"
+ else for s in [c.supers.first] do
+ write "\tinherit {s}[E]"
+ end
+ write "\t\tredefine id, make end"
+ write "create make"
+ write "feature"
+ write "\tid: INTEGER_64 {istk} do Result := {c.id} end"
+ write "\tf{c.id}: INTEGER_64 {istk} do Result := {c.id} end"
+ write "\ta{c.id}: INTEGER_64 {istk} attribute Result := {c.id} end"
+ write "make do aid := {c.id} end"
+ write "end"
+ file.close
+ end
+
+ file = new FileWriter.open("{dir}/app{name}.e")
+ write "class APP{name.to_upper}"
+ if se then
+ write "insert ARGUMENTS"
+ end
+ write "create make"
+ write "feature"
+
+ if se then
+ write "\tmake{istk}"
+ else
+ write "\tmake(args: ARRAY[STRING]){istk}"
+ end
+ write "\t\tlocal"
+ write "\t\t\ta: ROOT"
+ write "\t\t\tb: ROOT"
+ write "\t\t\ttmp: ROOT"
+ write "\t\tdo"
+ write "\t\t\tb := {ia.first} .make"
+ write "\t\t\ttmp := b"
+ for i in ia do
+ write "\t\t\tb := b.set_next({i} .make)"
+ end
+ write "\t\t\ttmp := b.set_next(tmp)"
+
+ write "\t\t\ta := {ia.last} .make"
+ write "\t\t\ttmp := a"
+ for i in [1..poly[ do
+ write "\t\t\ta := a.set_next({ia[ia.length - 1 - i]} .make)"
+ end
+ write "\t\t\ttmp := a.set_next(tmp);"
+ write "\t\t\ttest(b, b.next, 10, -100)"
+ write "\t\t\ttest(a, a.next, {loops}, 0)"
+ write "\t\tend"
+
+ write "\ttest(aa: ROOT; bb: ROOT; l: INTEGER_64; start: INTEGER_64){istk}"
+ write "\t\tlocal"
+ write "\t\t\ta: ROOT"
+ write "\t\t\tb: ROOT"
+ write "\t\t\ttmp: ROOT"
+ write "\t\t\ti: INTEGER_64"
+ write "\t\t\tj: INTEGER_64"
+ write "\t\t\tx: INTEGER_64"
+ locale(se)
+ write "\t\t\tloops: INTEGER_64"
+ write "\t\tdo"
+ write "\t\t\ta := aa"
+ write "\t\t\tb := bb"
+ write "\t\t\tx := start"
+ write "\t\t\tloops := l"
+ write "\t\t\tfrom i := loops until i<=0 loop"
+ write "\t\t\t\tfrom j := loops until j<=0 loop"
+ var test = "x >= 0"
+ if not dry then test = teste(se)
+ write "\t\t\t\t\tif {test} then"
+ write "\t\t\t\t\t\ttmp := a; a := b; b := tmp"
+ if check then write "\t\t\t\t\tx := x + 1"
+ write "\t\t\t\t\telse x := x + 1; a := a.next; b := b.next end"
+ write "\t\t\t\t\tj := j - 1"
+ write "\t\t\t\tend"
+ write "\t\t\t\tx := x + 1; a := a.next; b := b.next"
+ write "\t\t\t\ti := i - 1"
+ write "\t\t\tend"
+ write "\t\t\tprint(x.out)"
+ write "\t\t\tprint(\"%N\")"
+ write "\t\tend"
+ write "end"
+ file.close
+ end
+
+ fun initpython(res: Array[String]) do return
+ fun testpython: String do return "true"
+ fun writepython(dir: String, name: String)
+ do
+ var ia = new Array[String]
+ initpython(ia)
+ if ia.is_empty then
+ print "Python disabled"
+ return
+ end
+
+ dir = "{dir}/python"
+ dir.mkdir
+ file = new FileWriter.open("{dir}/{name}.py")
+
+ if use_root0 then
+ write "class Root0(object):"
+ else
+ write "class Root(object):"
+ end
+ write "\tdef id(self): return 0"
+ write "\tdef set_next(self, n):\n\t\tself.next = n\n\t\treturn n"
+ write "\tdef __init__(self): self.aid = self.id()"
+
+ if use_root0 then
+ write "class Root(Root0): pass"
+ end
+
+ for c in classes do
+ if c.supers.is_empty then
+ write "class {c}(Root):"
+ else
+ write "class {c}({c.supers.join(",")}):"
+ end
+ write "\tdef id(self): return {c.id}"
+ write "\tdef f{c.id}(self): return {c.id}"
+ write "\tdef __init__(self):"
+ write "\t\tsuper({c}, self).__init__()"
+ write "\t\ta{c.id} = {c.id}"
+ end
+
+ write "def test(a, b, loops, start):"
+ write "\tx = start"
+ write "\ti = loops"
+ write "\twhile i > 0:"
+ write "\t\tj = loops"
+ write "\t\twhile j > 0:"
+ var test = "x >= 0"
+ if not dry then test = testpython
+ write "\t\t\tif {test}:"
+ write "\t\t\t\ttmp = a; a = b; b = tmp"
+ if check then write "\t\t\t\tx += 1"
+ write "\t\t\telse:"
+ write "\t\t\t\tx = x + 1; a = a.next; b = b.next"
+ write "\t\t\tj -= 1"
+ write "\t\tx = x + 1; a = a.next; b = b.next"
+ write "\t\ti -= 1"
+ write "\tprint(x)"
+
+ write "b = {ia.first}"
+ write "tmp = b"
+ for i in ia do
+ write "b = b.set_next({i})"
+ end
+ write "b.next = tmp"
+ write "a = {ia.last}"
+ write "tmp = a"
+ for i in [1..poly[ do
+ write "a = a.set_next({ia[ia.length - 1 - i]})"
+ end
+ write "a.next = tmp"
+ write "test(b, b.next, 10, -100)"
+ write "test(a, a.next, {loops}, 0)"
+
+ file.close
+ end
+
+ var count = false
+
+ fun genall
+ do
+ var g = self
+ var outdir = args.first
+ var name = args[1]
+ var use_interfaces = self.use_interfaces
+ if args.length > 2 then g.dept = args[2].to_i
+ if args.length > 3 then loops = args[3].to_i
+ if args.length > 4 then use_interfaces = false
+
+ g.genhier
+
+ g.writenit(outdir, name)
+ g.writejava(outdir, name, use_interfaces)
+ g.writecsharp(outdir, name, use_interfaces)
+ g.writescala(outdir, name, use_interfaces)
+ g.writecpp(outdir, name)
+ g.writee(outdir, "{name}_se", true)
+ g.writee(outdir, name, false)
+ g.writepython(outdir, name)
+ end
+end
+
+var g = new Generator
+g.genall
--- /dev/null
+#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import bench_base
+
+class TypeTestDepthGenerator
+ super Generator
+
+ redef fun initnit(res)
+ do
+ for c in classes do
+ res.add "new {c}[Root]"
+ end
+ end
+
+ redef fun testnit
+ do
+ return "a.id >= {middle}"
+ end
+
+ redef fun initjava(res, interfaces)
+ do
+
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun testjava(interfaces)
+ do
+ return "a.id() >= {middle}"
+ end
+
+ redef fun initcsharp(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun testcsharp(interfaces)
+ do
+ return "a.Id() >= {middle}"
+ end
+
+ redef fun initscala(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}[Root]()"
+ end
+ end
+
+ redef fun testscala(interfaces)
+ do
+ return "a.id >= {middle}"
+ end
+
+ redef fun initcpp(res)
+ do
+ for c in classes do
+ res.add "new {c}<Root>()"
+ end
+ end
+
+ redef fun testcpp
+ do
+ return "a->id() >= {middle}"
+ end
+
+ redef fun inite(res, se)
+ do
+ for c in classes do
+ res.add "create \{{c}[ROOT]\}"
+ end
+ end
+
+ redef fun teste(se)
+ do
+ return "a.id >= {middle}"
+ end
+
+ redef fun initpython(res)
+ do
+ for c in classes do
+ res.add "{c}()"
+ end
+ end
+
+ redef fun testpython
+ do
+ return "a.id() >= {middle}"
+ end
+end
+
+var g = new TypeTestDepthGenerator
+g.genall
--- /dev/null
+#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import bench_base
+
+class TypeTestDepthGenerator
+ super Generator
+
+ redef fun initnit(res)
+ do
+ for c in classes do
+ res.add "new {c}[Root]"
+ end
+ end
+
+ redef fun initjava(res, interfaces)
+ do
+
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun initcsharp(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}<Root>()"
+ end
+ end
+
+ redef fun initscala(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{c}[Root]()"
+ end
+ end
+
+ redef fun initcpp(res)
+ do
+ for c in classes do
+ res.add "new {c}<Root>()"
+ end
+ end
+
+ redef fun inite(res, se)
+ do
+ for c in classes do
+ res.add "create \{{c}[ROOT]\}"
+ end
+ end
+
+ redef fun initpython(res)
+ do
+ for c in classes do
+ res.add "{c}()"
+ end
+ end
+end
+
+var g = new TypeTestDepthGenerator
+g.dry = true
+g.genall
--- /dev/null
+#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import bench_base
+
+class TypeTestCovarGenerator
+ super Generator
+
+ redef fun initnit(res)
+ do
+ for c in classes do
+ res.add "new {classes.first}[{c}[Root]]"
+ end
+
+ end
+
+ redef fun testnit
+ do
+ return "a isa {classes.first}[{classes[middle]}[Root]]"
+ end
+
+ redef fun initcsharp(res, interfaces)
+ do
+ var tagc = ""
+ if interfaces then tagc = "X"
+ for c in classes do
+ res.add "new {tagc}{classes.first}<{c}<Root>>()"
+ end
+ end
+
+ redef fun testcsharp(interfaces)
+ do
+ return "a is {classes.first}<{classes[middle]}<Root>>"
+ end
+
+ redef fun inite(res, se)
+ do
+ for c in classes do
+ res.add "create \{{classes.first}[{c}[ROOT]]\}"
+ end
+ end
+
+ redef fun teste(se)
+ do
+ write "\t\t\t\t\tto ?= a"
+ return "to /= Void"
+ end
+
+ redef fun locale(se)
+ do
+ write "\t\t\tto: detachable {classes.first}[{classes[middle]}[ROOT]]"
+ end
+end
+
+var g = new TypeTestCovarGenerator
+g.genall
#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
import bench_base
redef fun inite(res, se)
do
for c in classes do
- res.add "create \{{c}[ROOT]\} a"
+ res.add "create \{{c}[ROOT]\}"
end
end
redef fun locale(se)
do
- write "\t\t\tto: {classes[middle]}[ROOT]"
+ write "\t\t\tto: detachable {classes[middle]}[ROOT]"
+ end
+
+ redef fun initpython(res)
+ do
+ for c in classes do
+ res.add "{c}()"
+ end
+ end
+ redef fun testpython
+ do
+ return "isinstance(a, {classes[middle]})"
end
end
#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
import bench_base
import pipeline
redef fun initnit(res)
do
res.add "new {classes.last}[Root]"
- for c in classes.skip_tail(1) do
+ for c in classes.iterator.skip_tail(1) do
res.add "new {c}[Root]"
end
end
var tagc = ""
if interfaces then tagc = "X"
res.add "new {tagc}{classes.last}<Root>()"
- for c in classes.skip_tail(1) do
+ for c in classes.iterator.skip_tail(1) do
res.add "new {tagc}{c}<Root>()"
end
end
var tagc = ""
if interfaces then tagc = "X"
res.add "new {tagc}{classes.last}<Root>()"
- for c in classes.skip_tail(1) do
+ for c in classes.iterator.skip_tail(1) do
res.add "new {tagc}{c}<Root>()"
end
end
var tagc = ""
if interfaces then tagc = "X"
res.add "new {tagc}{classes.last}[Root]()"
- for c in classes.skip_tail(1) do
+ for c in classes.iterator.skip_tail(1) do
res.add "new {tagc}{c}[Root]()"
end
end
redef fun initcpp(res)
do
res.add "new {classes.last}<Root>()"
- for c in classes.skip_tail(1) do
+ for c in classes.iterator.skip_tail(1) do
res.add "new {c}<Root>()"
end
end
redef fun inite(res, se)
do
- res.add "create \{{classes.last}[ROOT]\} a"
- for c in classes.skip_tail(1) do
- res.add "create \{{c}[ROOT]\} a"
+ res.add "create \{{classes.last}[ROOT]\}"
+ for c in classes.iterator.skip_tail(1) do
+ res.add "create \{{c}[ROOT]\}"
end
end
redef fun locale(se)
do
- write "\t\t\tto: {classes.last}[ROOT]"
+ write "\t\t\tto: detachable {classes.last}[ROOT]"
+ end
+
+ redef fun initpython(res)
+ do
+ res.add "{classes.last}()"
+ for c in classes.iterator.skip_tail(1) do
+ res.add "{c}()"
+ end
+ end
+ redef fun testpython
+ do
+ return "not isinstance(a, {classes.last})"
end
end
#!/usr/bin/env nit
+# This file is part of NIT ( http://www.nitlanguage.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.
import bench_base
fun clanit(i: Int): String
do
var s = new FlatBuffer
- s.append("{classes.first}[" * i)
+ s.append("{classes[i]}[")
+ s.append("{classes.first}[" * (dept-1))
s.append("Root")
- s.append("]" * i)
+ s.append("]" * dept)
return s.to_s
end
redef fun initnit(res)
do
- for i in [1..dept] do
+ for i in [0..dept[ do
res.add "new {clanit(i)}"
end
fun clajava(i: Int): String
do
var s = new FlatBuffer
- s.append("{classes.first}<" * i)
+ s.append("{classes[i]}<")
+ s.append("{classes.first}<" * (dept-1))
s.append("Root")
- s.append(">" * i)
+ s.append(">" * dept)
return s.to_s
end
- redef fun initjava(res, interfaces)
- do
-
- var tagc = ""
- if interfaces then tagc = "X"
- for i in [1..dept] do
- res.add "new {tagc}{clajava(i)}()"
- end
- end
-
- redef fun testjava(interfaces)
- do
- return "a instanceof {classes.first}<?>"
- end
-
redef fun initcsharp(res, interfaces)
do
var tagc = ""
if interfaces then tagc = "X"
- for i in [1..dept] do
+ for i in [0..dept[ do
res.add "new {tagc}{clajava(i)}()"
end
end
return "a is {clajava(middle)}"
end
- redef fun initscala(res, interfaces)
- do
- var tagc = ""
- if interfaces then tagc = "X"
- for i in [1..dept] do
- res.add "new {tagc}{clanit(i)}()"
- end
- end
-
- redef fun testscala(interfaces)
- do
- return "a.isInstanceOf[{clanit(middle)}]"
- end
-
fun clacpp(i: Int): String
do
var s = new FlatBuffer
- s.append("{classes.first}<" * i)
+ s.append("{classes[i]}<")
+ s.append("{classes.first}<" * (dept-1))
s.append("Root")
- s.append("*>" * i)
+ s.append("*>" * dept)
return s.to_s
end
redef fun initcpp(res)
do
- for i in [1..dept] do
+ for i in [0..dept[ do
res.add "new {clacpp(i)}()"
end
end
fun clae(i: Int): String
do
var s = new FlatBuffer
- s.append("{classes.first}[" * i)
+ s.append("{classes[i]}[")
+ s.append("{classes.first}[" * (dept-1))
s.append("ROOT")
- s.append("]" * i)
+ s.append("]" * dept)
return s.to_s
end
redef fun inite(res, se)
do
- for i in [1..dept] do
- res.add "create \{{clae(i)}\} a"
+ for i in [0..dept[ do
+ res.add "create \{{clae(i)}\}"
end
end
redef fun locale(se)
do
- write "\t\t\tto: {clae(middle)}"
+ write "\t\t\tto: detachable {clae(middle)}"
end
end