1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* __ *\
** ________ ___ / / ___ Scala benchmark suite **
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
** $Id$
\* */
package benchmarks;
/** Imperative for construct. Translated from MLton benchmarking suite */
class For {
def impFor[A](start: Int, stop: Int, f: Int => A) = {
var i = start;
def loop: Unit = if (i >= stop) ()
else { f(i); i = i + 1; loop }
loop;
}
}
object impfor extends For with scala.testing.Benchmark {
def doit: Unit = {
var x = 0;
impFor(0, 10, t =>
impFor(0, 10, t =>
impFor(0, 10, t =>
impFor(0, 10, t =>
impFor(0, 10, t =>
impFor(0, 10, t =>
impFor(0, 10, t => x = x + 1))))))); // 7 inner loops
if (x != 10000000) {
Console.println("Error");
System.exit(1);
}
}
def run: Unit = doit;
}
|