From 02b2da63409af6a28824cbb74d00d0ec04518c8d Mon Sep 17 00:00:00 2001 From: Jean-Remi Desjardins Date: Sun, 23 Dec 2012 16:44:59 -0500 Subject: SI-5017 Poor performance of :+ operator on Arrays Control performance of :+ and +: operator on my machine were 700-800 ms After adding size hint on the implementation in SeqLike, it went down to 500-600 ms But with specialixed implementation in ArrayOps, brings it down to 300-400 ms Unfortunatly, this method will only be called when the Array object is being referenced directly as it's type, but that should be the case enough times to justify the extra method. I ended up removing the sizeHint in SeqLike because it made the execution of the "benchmark" slower when the Array was being manipulated as a Seq. Side note: Interestingly enough, the benchmark performed better on my virtualized Fedora 17 with JDK 7 than natively on Mac OS X with JDK 6 --- test/files/run/array-addition.check | 4 ++++ test/files/run/array-addition.scala | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/files/run/array-addition.check create mode 100644 test/files/run/array-addition.scala (limited to 'test') diff --git a/test/files/run/array-addition.check b/test/files/run/array-addition.check new file mode 100644 index 0000000000..7bfbd9c711 --- /dev/null +++ b/test/files/run/array-addition.check @@ -0,0 +1,4 @@ +Array(1, 2, 3, 4) +Array(1, 2, 3, 4) +Array(1) +Array(1) diff --git a/test/files/run/array-addition.scala b/test/files/run/array-addition.scala new file mode 100644 index 0000000000..8def48e85c --- /dev/null +++ b/test/files/run/array-addition.scala @@ -0,0 +1,11 @@ +object Test { + def prettyPrintArray(x: Array[_]) = println("Array(" + x.mkString(", ") + ")") + + def main(args: Array[String]): Unit = { + prettyPrintArray(Array(1,2,3) :+ 4) + prettyPrintArray(1 +: Array(2,3,4)) + prettyPrintArray(Array() :+ 1) + prettyPrintArray(1 +: Array()) + } +} + -- cgit v1.2.3