benches: added C# to gen micro benches
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 18 Feb 2013 17:32:29 +0000 (12:32 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 11 Mar 2013 19:49:22 +0000 (15:49 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/benchs/gen.nit
src/run_bench.sh

index 74c4b43..9dc2d32 100644 (file)
@@ -235,6 +235,109 @@ class Generator
                file.close
        end
 
+       fun writecsharp(name: String, interfaces: Bool)
+       do
+               var cl = ""
+               if interfaces then cl = "X"
+               file = new OFStream.open("{name}.cs")
+               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} "
+                       else
+                               write "class {c} "
+                       end
+                       if c.supers.is_empty then
+                               write "\t: Root"
+                       else for s in [c.supers.first] do
+                               write "\t: {s}"
+                       end
+                       if interfaces then
+                               write "\{\}"
+                               write "class X{c} : {c}"
+                       end
+                       write "\{"
+                       write "\tpublic int Id() \{ return {c.id}; \}"
+                       write "\}"
+               end
+               write "class L<E>"
+               if interfaces then
+                       write ": Root \{"
+               else
+                       write ": Root \{"
+               end
+               write "\tE _item;"
+               write "\tpublic E Item() \{ return _item; \}"
+               write "\tpublic void SetItem(E i) \{ _item = i; \}"
+               write "\tL<E> _next;"
+               write "\tpublic L<E> Next() \{ return _next; \}"
+               write "\tpublic void SetNext(L<E> n) \{ _next = n; \}"
+               write "\tpublic L(E i, L<E> n) \{ SetItem(i); SetNext(n); \}"
+               write "\tpublic int Id() \{ return -1; \}"
+               write "\}"
+
+               write "static L<Root> Fill() \{"
+               write "\tL<Root> head = null;"
+               for c in classes do
+                       write "\tL<{c}> l{c} = new L<{c}>(new {cl}{c}(), null);"
+                       write "\thead = new L<Root>(l{c}, head);"
+               end
+               write "\thead = null;"
+               write "for (int x=0; x<{arraylen}; x++) \{"
+               for i in [0..listlen[ do
+                       var c = unlist[i]
+                       write "\tL<{c}> l{i} = new L<{c}>(new {cl}{c}(), null);"
+                       write "\thead = new L<Root>(l{i}, head);"
+               end
+               write "\}"
+               write "return head;"
+               write "\}"
+
+               write "static int Run(L<Root> head1, L<Root> head2) \{"
+               write "\tint cpt = 0;"
+               write "\tint y = {loops/list.length};"
+               write "\twhile (y > 0) \{;"
+               write "\tL<Root> n1 = head1;"
+               write "\tL<Root> n2 = head2;"
+               write "\twhile (n1 != null) \{"
+               for i in [0..listlen[ do
+                       var c = list[i]
+                       write "\t\tRoot l{i} = n1.Item();"
+                       write "\t\tL<{c}> lc{i} = (L<{c}>)l{i};"
+                       write "\t\t{c} c{i} = lc{i}.Item();"
+                       write "\t\tn1 = n1.Next();"
+                       if count then
+                               write "\t\tif (c{i}.Id() == {c.id}) cpt += 1;"
+                       end
+                       write "\t\tRoot l2_{i} = n2.Item();"
+                       write "\t\tL<{c}> lc2_{i} = (L<{c}>)l2_{i};"
+                       write "\t\tlc2_{i}.SetItem(c{i});"
+                       write "\t\tn2 = n2.Next();"
+               end
+               write "\t\}"
+               write "y -= 1;"
+               write "\}"
+               write "return cpt;"
+               write "\}"
+
+               write "static void Main(string[] args) \{"
+               write "L<Root> head = Fill();"
+               write "int loops = 25;"
+               write "if (args.Length > 0) loops = int.Parse(args[0]);"
+               write "for (int x=0; x<loops; x++) \{"
+               write "\tint cpt = Run(head, head);"
+               write "\tSystem.Console.WriteLine(\"\" + x + \":\\t\" + cpt);"
+               write "\}"
+               write "\}"
+               write "\}"
+               file.close
+       end
+
        fun writescala(name: String)
        do
                var cl = ""
@@ -556,6 +659,7 @@ end
 g.genhier
 g.writenit(name)
 g.writejava(name, true)
+g.writecsharp(name, true)
 g.writescala(name)
 g.writecpp(name)
 g.writee("{name}_se", true)
index b33faf8..1388d6c 100755 (executable)
@@ -548,6 +548,12 @@ function bench_typetest_languages()
                bench_command "$b" "" scala "${t}_$b" $s
        done
 
+       prepare_res "$name-cs.dat" "c#" "c#"
+       for b in $seq; do
+               run_command gmcs ${t}_$b.cs
+               bench_command "$b" "" mono "${t}_$b.exe" $s
+       done
+
        prepare_res "$name-es.dat" "es" "es"
        for b in $seq; do
                run_command ec -clean -finalize ${t}_$b/app${t}_$b.e