--- a/scala/ex.scala Fri Mar 08 11:31:04 2013 +0000
+++ b/scala/ex.scala Sun Mar 10 07:10:50 2013 +0000
@@ -90,8 +90,11 @@
def test_comp2(f: Rec, ns: Int*) = {
val (abc_f, arity, _) = compile_rec(f)
val abc_map = (0 until ns.length).zip(ns).toMap[Int, Int]
+ val start = System.nanoTime()
val res = (abc_f.run(abc_map))(arity)
- ("Result: " + res + " length: " + abc_f.p.length)
+ val end = System.nanoTime()
+ val time = (end - start)/1.0e9
+ ("Result: " + res + " length: " + abc_f.p.length + " time: " + "%.5f".format(time))
}
println("S(3) " + test_comp2(S, 3))
@@ -102,7 +105,7 @@
println("Power(3, 4) " + test_comp2(Power, 3, 4))
println("Minus(30, 4) " + test_comp2(Minus, 30, 4))
println("Fact(5) " + test_comp2(Fact, 5))
-//println("Prime(5) " + test_comp2(Prime, 5))
+println("Prime(5) " + test_comp2(Prime, 5))
//println("Prime(4) " + test_comp2(Prime, 4))
println("Strt(1)(2) " + test_comp2(Strt(1), 2))
@@ -110,8 +113,11 @@
def test_comp1(f: Rec, ns: Int*) = {
val (abc_f, arity, _) = compile_rec(f)
val tm = toTM(abc_f.p) :+ TMMopup(arity)
+ val start = System.nanoTime()
val res = tm.run(Tape(ns.toList))
- ("length: " + tm.p.length + " tape: " + arity + "\nResult: " + res)
+ val end = System.nanoTime()
+ val time = (end - start)/1.0e9
+ ("length: " + tm.p.length + " tape: " + arity + " time: " + "%.5f".format(time) + "\nResult: " + res)
}
println("")