99 |
100 |
100 |
101 |
101 //one or zero |
102 //one or zero |
102 def OPT(r: Rexp) = ALT(r, ONE) |
103 def OPT(r: Rexp) = ALT(r, ONE) |
103 |
104 |
104 def EVIL(n: Int) = SEQ(NTIMES(OPT("a"), n), NTIMES("a", n)) |
105 def EVIL1(n: Int) = SEQ(NTIMES(OPT("a"), n), NTIMES("a", n)) |
|
106 val EVIL2 = SEQ(STAR("a"), "b") |
105 |
107 |
106 def time_needed[T](i: Int, code: => T) = { |
108 def time_needed[T](i: Int, code: => T) = { |
107 val start = System.nanoTime() |
109 val start = System.nanoTime() |
108 for (j <- 1 to i) code |
110 for (j <- 1 to i) code |
109 val end = System.nanoTime() |
111 val end = System.nanoTime() |
110 (end - start)/(i * 1.0e9) |
112 (end - start)/(i * 1.0e9) |
111 } |
113 } |
112 |
114 |
113 val i = 5000000 |
115 val i = 5000 |
114 println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL(i), "a" * i)))) |
116 println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL1(i), "a" * i)))) |
115 |
117 |
116 for (i <- 1 to 800001 by 10000) { |
118 //for (i <- 1 to 10000 by 1000) { |
117 println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL(i), "a" * i)))) |
119 // println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL1(i), "a" * i)))) |
|
120 //} |
|
121 |
|
122 for (i <- 1 to 6000000 by 500000) { |
|
123 println(i + " " + "%.5f".format(time_needed(10, matcher(EVIL2, "a" * i)))) |
118 } |
124 } |
119 |
125 |
120 |
|