diff options
Diffstat (limited to 'test/benchmark/sources/impfor/impfor.scala')
-rw-r--r-- | test/benchmark/sources/impfor/impfor.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/benchmark/sources/impfor/impfor.scala b/test/benchmark/sources/impfor/impfor.scala new file mode 100644 index 0000000000..f02a4ba31b --- /dev/null +++ b/test/benchmark/sources/impfor/impfor.scala @@ -0,0 +1,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; +} |