summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-08-23 08:51:57 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-08-23 08:51:57 +0000
commit7adc188a0749bb5d16ffb4f43273d149969aa2d3 (patch)
tree7a0609ff2c8f8e8355f2e14c7232d6a47b33ef2b /src
parentbd6914a7c215bd8cfadf858bf43b64a4d59860b9 (diff)
downloadscala-7adc188a0749bb5d16ffb4f43273d149969aa2d3.tar.gz
scala-7adc188a0749bb5d16ffb4f43273d149969aa2d3.tar.bz2
scala-7adc188a0749bb5d16ffb4f43273d149969aa2d3.zip
Added setup and teardown methods.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/testing/Benchmark.scala23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/library/scala/testing/Benchmark.scala b/src/library/scala/testing/Benchmark.scala
index 035c1b41f5..19ae1b9c3f 100644
--- a/src/library/scala/testing/Benchmark.scala
+++ b/src/library/scala/testing/Benchmark.scala
@@ -38,7 +38,13 @@ import compat.Platform
*/
trait Benchmark {
- /** this method should be implemented by the concrete benchmark */
+ /** this method should be implemented by the concrete benchmark.
+ * This method is called by the benchmarking code for a number of times.
+ * The GC is called before each call to 'run'.
+ *
+ * @see setUp
+ * @see tearDown
+ */
def run()
var multiplier = 1
@@ -59,17 +65,28 @@ trait Benchmark {
i += 1
}
val stopTime = Platform.currentTime
+ tearDown
Platform.collectGarbage
stopTime - startTime
}
- /** Prepare any data needed by the benchmark, but which should not
- * be measured.
+ /** Prepare any data needed by the benchmark, but whose execution time
+ * should not be measured. This method is run before each call to the
+ * benchmark payload, 'run'.
*/
def setUp {
}
+ /** Perform cleanup operations after each 'run'. For micro benchmarks,
+ * think about using the result of 'run' in a way that prevents the JVM
+ * to dead-code eliminate the whole 'run' method. For instance, print or
+ * write the results to a file. The execution time of this method is not
+ * measured.
+ */
+ def tearDown {
+ }
+
/** a string that is written at the beginning of the output line
* that contains the timings. By default, this is the class name.
*/