progs/re2.scala
changeset 631 f618dd4de24a
parent 623 47a299e7010f
--- a/progs/re2.scala	Wed Sep 25 11:24:34 2019 +0100
+++ b/progs/re2.scala	Wed Sep 25 23:56:36 2019 +0100
@@ -41,7 +41,7 @@
   case c::s => ders(s, der(c, r))
 }
 
-def matches(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r))
+def matcher(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r))
 
 
 // the optional regular expression: one or zero times
@@ -59,19 +59,19 @@
   val start = System.nanoTime()
   for (j <- 1 to i) code
   val end = System.nanoTime()
-  "%.5f".format((end - start) / (i * 1.0e9))
+  (end - start) / (i * 1.0e9)
 }
 
 
 
 // test: (a?{n}) (a{n})
 for (i <- 0 to 1000 by 100) {
-  println(s"$i: ${time_needed(2, matches(EVIL1(i), "a" * i))}")
+  println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f")
 }
 
 // test: (a*)* b
-for (i <- 1 to 21) {
-  println(s"$i: ${time_needed(2, matches(EVIL2, "a" * i))}")
+for (i <- 0 to 20) {
+  println(f"$i: ${time_needed(2, matcher(EVIL2, "a" * i))}%.5f")
 }