From 7adc188a0749bb5d16ffb4f43273d149969aa2d3 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Mon, 23 Aug 2010 08:51:57 +0000 Subject: Added setup and teardown methods. --- src/library/scala/testing/Benchmark.scala | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') 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. */ -- cgit v1.2.3