progs/re4.scala
changeset 412 1cef3924f7a2
parent 407 4b454a6d1814
child 414 065ca01b62ae
--- a/progs/re4.scala	Sun Aug 21 18:15:53 2016 +0200
+++ b/progs/re4.scala	Mon Aug 22 09:12:03 2016 +0200
@@ -1,4 +1,5 @@
 import scala.annotation.tailrec    
+import scala.language.implicitConversions
     
 abstract class Rexp {
   def simp : Rexp = this
@@ -101,7 +102,8 @@
 //one or zero
 def OPT(r: Rexp) = ALT(r, ONE)
 
-def EVIL(n: Int) = SEQ(NTIMES(OPT("a"), n), NTIMES("a", n))
+def EVIL1(n: Int) = SEQ(NTIMES(OPT("a"), n), NTIMES("a", n))
+val EVIL2 = SEQ(STAR("a"), "b")
 
 def time_needed[T](i: Int, code: => T) = {
   val start = System.nanoTime()
@@ -110,11 +112,14 @@
   (end - start)/(i * 1.0e9)
 }
 
-val i = 5000000
-println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL(i), "a" * i))))
+val i = 5000
+println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL1(i), "a" * i))))
 
-for (i <- 1 to 800001 by 10000) {
-  println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL(i), "a" * i))))
+//for (i <- 1 to 10000 by 1000) {
+//  println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL1(i), "a" * i))))
+//}
+
+for (i <- 1 to 6000000 by 500000) {
+  println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL2, "a" * i))))
 }
 
-