summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/TestUtil.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/partest/scala/tools/partest/TestUtil.scala b/src/partest/scala/tools/partest/TestUtil.scala
new file mode 100644
index 0000000000..b86a8e2c7f
--- /dev/null
+++ b/src/partest/scala/tools/partest/TestUtil.scala
@@ -0,0 +1,36 @@
+package scala.tools.partest
+
+trait TestUtil {
+ /** Given function and block of code, evaluates code block,
+ * calls function with nanoseconds elapsed, and returns block result.
+ */
+ def timed[T](f: Long => Unit)(body: => T): T = {
+ val start = System.nanoTime
+ val result = body
+ val end = System.nanoTime
+
+ f(end - start)
+ result
+ }
+ /** Times body and returns (nanos, result).
+ */
+ def alsoNanos[T](body: => T): (Long, T) = {
+ var nanos = 0L
+ val result = timed(nanos = _)(body)
+
+ (nanos, result)
+ }
+ def nanos(body: => Unit): Long = alsoNanos(body)._1
+
+ def verifySpeed(body1: => Unit, body2: => Unit, acceptableMultiple: Double) = {
+ val t1 = nanos(body1).toDouble
+ val t2 = nanos(body2).toDouble
+ val mult = if (t1 > t2) t1 / t2 else t2 / t1
+
+ assert(mult <= acceptableMultiple, "Performance difference too great: multiple = " + mult)
+ }
+}
+
+object TestUtil extends TestUtil {
+
+} \ No newline at end of file