summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-06-08 06:19:40 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-06-08 06:19:40 -0700
commit1fac5bcbbcb9bbfc5953c29574f3952b97945921 (patch)
treea1f63a911b25a05eaed9e05972702913f17fe533 /test
parent5cd82554069508af769d59f9e41af36f6524b4cc (diff)
parent0291797fec629c750cefea17ff23c9adc236fec4 (diff)
downloadscala-1fac5bcbbcb9bbfc5953c29574f3952b97945921.tar.gz
scala-1fac5bcbbcb9bbfc5953c29574f3952b97945921.tar.bz2
scala-1fac5bcbbcb9bbfc5953c29574f3952b97945921.zip
Merge pull request #672 from axel22/issue/5857
Fixes SI-5857. More efficient min and max in Range and NumericRange
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t5857.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/files/run/t5857.scala b/test/files/run/t5857.scala
new file mode 100644
index 0000000000..bf67bedf54
--- /dev/null
+++ b/test/files/run/t5857.scala
@@ -0,0 +1,45 @@
+
+
+
+object Test {
+
+ def time[U](b: =>U): Long = {
+ val start = System.currentTimeMillis
+ b
+ val end = System.currentTimeMillis
+
+ end - start
+ }
+
+ def main(args: Array[String]) {
+ val sz = 1000000000
+
+ val range = 1 to sz
+ check { assert(range.min == 1, range.min) }
+ check { assert(range.max == sz, range.max) }
+
+ val descending = sz to 1 by -1
+ check { assert(descending.min == 1) }
+ check { assert(descending.max == sz) }
+
+ val numeric = 1.0 to sz.toDouble by 1
+ check { assert(numeric.min == 1.0) }
+ check { assert(numeric.max == sz.toDouble) }
+
+ val numdesc = sz.toDouble to 1.0 by -1
+ check { assert(numdesc.min == 1.0) }
+ check { assert(numdesc.max == sz.toDouble) }
+ }
+
+ def check[U](b: =>U) {
+ val exectime = time {
+ b
+ }
+
+ // whatever it is, it should be less than, say, 250ms
+ // if `max` involves traversal, it takes over 5 seconds on a 3.2GHz i7 CPU
+ //println(exectime)
+ assert(exectime < 250, exectime)
+ }
+
+}