| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Fri, 04 Nov 2022 12:07:40 +0000 | |
| changeset 894 | 4d5058706f1b | 
| parent 742 | 155426396b5f | 
| permissions | -rw-r--r-- | 
| 49 | 1  | 
|
2  | 
// measures the time a function needs  | 
|
3  | 
def time_needed[T](i: Int, code: => T) = {
 | 
|
4  | 
val start = System.nanoTime()  | 
|
5  | 
for (j <- 1 to i) code  | 
|
6  | 
val end = System.nanoTime()  | 
|
7  | 
(end - start)/(i * 1.0e9)  | 
|
8  | 
}  | 
|
9  | 
||
10  | 
||
11  | 
for (i <- 1 to 10001 by 300) {
 | 
|
12  | 
  val re = ("((a?){" + i + "})(a{" + i + "})")
 | 
|
13  | 
  println(i + " " + "%.5f".format(time_needed(1, ("a" * i).matches(re))))  
 | 
|
14  | 
}  | 
|
15  | 
||
16  | 
||
17  |