summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/scala
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-07 10:15:32 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-07 10:15:32 +0000
commite67f56076624ea83383901934a30280d7f97380f (patch)
treea28b45d7a79ff9002735ea225b3a4733ac4d0234 /test/benchmarks/src/scala
parentdd396886d0da88326e5e4772af4d8813360ea8a5 (diff)
downloadscala-e67f56076624ea83383901934a30280d7f97380f.tar.gz
scala-e67f56076624ea83383901934a30280d7f97380f.tar.bz2
scala-e67f56076624ea83383901934a30280d7f97380f.zip
Adding parallel collections to trunk.
sabbus also edited to add parallel collections to the library jar - review by phaller
Diffstat (limited to 'test/benchmarks/src/scala')
-rw-r--r--test/benchmarks/src/scala/collection/parallel/Benchmarking.scala178
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/Bench.scala122
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Arrays.scala63
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Dummy.scala22
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/IntAccess.scala68
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/ObjectAccess.scala75
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala39
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/UnknownManif.scala38
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala58
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala51
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala213
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala54
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Foreach.scala45
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/IntInit.scala30
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala51
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Lookup.scala57
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/AggregateLight.scala39
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Companion.scala9
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CopyToArray.scala21
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Corresponds.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountHeavy.scala36
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountLight.scala21
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountList.scala30
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DiffHalf.scala48
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DropMany.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ExistsLight.scala49
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FilterLight.scala64
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FindLight.scala52
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FlatMapLight.scala24
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallHeavy.scala59
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallLight.scala46
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallQuickStop.scala46
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallStop80k.scala46
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachHeavy.scala42
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachLight.scala26
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IndexWhere.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IntersectHalf.scala48
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/LastIndexWhere.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MapLight.scala27
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala84
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MinLight.scala28
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PadToDouble.scala53
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartialMapLight.scala24
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartitionLight.scala61
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PatchHalf.scala46
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PlusPlus.scala29
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceHeavy.scala22
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceLight.scala50
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceList.scala53
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceNew.scala30
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReducePrime.scala65
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/RemoveDuplicates.scala44
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Resettable.scala127
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Reverse.scala35
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReverseMap.scala48
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SameElementsLong.scala45
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SegmentLength.scala42
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SequentialOps.scala547
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceFew.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMany.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMedium.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SpanLight.scala62
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SplitHalf.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SumLight.scala28
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeMany.scala47
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeWhileLight.scala61
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_range/RangeBenches.scala208
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_view/SeqViewBenches.scala50
68 files changed, 4162 insertions, 0 deletions
diff --git a/test/benchmarks/src/scala/collection/parallel/Benchmarking.scala b/test/benchmarks/src/scala/collection/parallel/Benchmarking.scala
new file mode 100644
index 0000000000..371ebccef4
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/Benchmarking.scala
@@ -0,0 +1,178 @@
+package scala.collection.parallel
+
+
+import scala.collection.mutable.LinkedHashSet
+
+import benchmarks._
+
+
+/**
+ * All benchmarks are registered here.
+ *
+ * @author prokopec
+ */
+trait BenchmarkRegister {
+
+ val benchcreators = LinkedHashSet[BenchCompanion]()
+
+ def register(companion: BenchCompanion) = benchcreators += companion
+
+ // parallel array benchmarks
+ register(parallel_array.ReduceLight)
+ register(parallel_array.ReduceNew)
+ register(parallel_array.ReduceList)
+ register(parallel_array.ReducePrime)
+ register(parallel_array.ReduceHeavy)
+ register(parallel_array.CountLight)
+ register(parallel_array.CountList)
+ register(parallel_array.CountHeavy)
+ register(parallel_array.ForeachLight)
+ register(parallel_array.ForeachHeavy)
+ register(parallel_array.SumLight)
+ register(parallel_array.MinLight)
+ register(parallel_array.MapLight)
+ register(parallel_array.FilterLight)
+ register(parallel_array.PartitionLight)
+ register(parallel_array.PartialMapLight)
+ register(parallel_array.FlatMapLight)
+ register(parallel_array.PlusPlus)
+ register(parallel_array.ForallLight)
+ register(parallel_array.ForallQuickStop)
+ register(parallel_array.ForallStop80k)
+ register(parallel_array.ForallHeavy)
+ register(parallel_array.ExistsLight)
+ register(parallel_array.FindLight)
+ register(parallel_array.TakeMany)
+ register(parallel_array.DropMany)
+ register(parallel_array.SliceMany)
+ register(parallel_array.SliceMedium)
+ register(parallel_array.SliceFew)
+ register(parallel_array.SplitHalf)
+ register(parallel_array.TakeWhileLight)
+ register(parallel_array.SpanLight)
+ register(parallel_array.CopyToArray)
+ register(parallel_array.SegmentLength)
+ register(parallel_array.IndexWhere)
+ register(parallel_array.LastIndexWhere)
+ register(parallel_array.Reverse)
+ register(parallel_array.ReverseMap)
+ register(parallel_array.SameElementsLong)
+ register(parallel_array.Corresponds)
+ register(parallel_array.DiffHalf)
+ register(parallel_array.IntersectHalf)
+ register(parallel_array.RemoveDuplicates)
+ register(parallel_array.PatchHalf)
+ register(parallel_array.PadToDouble)
+ register(parallel_array.AggregateLight)
+ register(parallel_array.MatrixMultiplication)
+
+ // parallel views
+ register(parallel_view.DummyViewBenchList.Reduce)
+ register(parallel_view.DummyViewBenchList.MediumReduce)
+ register(parallel_view.DummyViewBenchList.ModifyThenReduce)
+ register(parallel_view.DummyViewBenchList.ModifyThenForce)
+
+ // parallel ranges
+ register(parallel_range.RangeBenches.Reduce)
+ register(parallel_range.RangeBenches.ReduceMedium)
+ register(parallel_range.RangeBenches.ForeachAdd)
+ register(parallel_range.RangeBenches.ForeachAddCollatz)
+ register(parallel_range.RangeBenches.ForeachModify)
+ register(parallel_range.RangeBenches.ForeachModifyMedium)
+ register(parallel_range.RangeBenches.ForeachModifyHeavy)
+ register(parallel_range.RangeBenches.MapLight)
+ register(parallel_range.RangeBenches.MapMedium)
+
+ // array benchmarks
+ register(arrays.ObjectAccess)
+ register(arrays.IntAccess)
+
+ // hash benchmarks
+ register(hashtries.Foreach)
+ register(hashtries.Iterate)
+ register(hashtries.Construct)
+ register(hashtries.Lookup)
+}
+
+
+/**
+ * Serves as an entrypoint to run all the benchmarks.
+ */
+object Benchmarking extends BenchmarkRegister {
+
+ def printHelp {
+ println("Must enter at least four arguments: <collection> <benchmark> <size of the collection> <type>")
+ println(" Example: ParallelArray reduce-light 50000 par")
+ println(" Example: ParallelArray -all 50000 par")
+ println
+ println("General synthax: <collection> <benchmark> <size> <type> <parallelism-level>")
+ println(" <collection> - name of the collection to test, `-all` runs benchmarks for all collections")
+ println(" <benchmark> - name of the specific benchmark, `-all` runs all benchmarks for the chosen collections")
+ println(" <size> - the size (number of elements) of the collection, or `-default` for default size per benchmark")
+ println(" <type> - `seq` for benchmarking sequential version of the functionality")
+ println(" `par` for benchmarking parallel version of the functionality")
+ println(" `<something-else>` for running comparison benchmarks")
+ println(" `-all` for running sequential, parallel and comparison benchmarks")
+ println(" <parallelism-level> - the level of parallelism used (default 2)")
+ }
+
+ def otherOptions(args: Array[String]) {
+ if (args.length == 0) printHelp
+ else args(0) match {
+ case "-list" => // lists all benchmarks
+ for (bc <- benchcreators) println(bc.fullname)
+ case _ => printHelp
+ }
+ }
+
+ def main(args: Array[String]) {
+ if (args.length < 4) {
+ otherOptions(args)
+ return
+ }
+
+ val collname = args(0)
+ val benchname = args(1)
+ val size = if (args(2) == "-default") -1 else args(2).toInt
+ val tpe = args(3)
+ val parlevel = if (args.length >= 5) args(4).toInt else 2
+
+ // find all benchmarks to run
+ val benches = benchcreators.filter(comp => {
+ (collname, benchname) match {
+ case ("-all", "-all") => true
+ case ("-all", bn) if (benchname != "-all") => bn == comp.benchName
+ case (cn, "-all") if (collname != "-all") => cn == comp.collectionName
+ case (cn, bn) => cn == comp.collectionName && bn == comp.benchName
+ }
+ }).flatMap(comp => {
+ val collsz = if (size != -1) size else comp.defaultSize
+ if (tpe != "-all") List(comp.apply(collsz, parlevel, tpe))
+ else for (benchtype <- "seq" :: "par" :: comp.comparisons)
+ yield comp.apply(collsz, parlevel, benchtype)
+ })
+
+ println("Running benchmarks...")
+ for (b <- benches) b.executeBenchmark
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/Bench.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/Bench.scala
new file mode 100644
index 0000000000..10e6201709
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/Bench.scala
@@ -0,0 +1,122 @@
+package scala.collection.parallel.benchmarks
+
+
+import scala.collection._
+import scala.testing.Benchmark
+
+
+
+trait BenchCompanion {
+ def benchName: String
+ def collectionName: String
+ def fullname = collectionName + "." + benchName
+ def defaultSize = 100000
+ def comparisons = List[String]()
+ def apply(sz: Int, parallelism: Int, what: String): Bench
+}
+
+
+/**
+ * An interface for all benchmark classes.
+ * A benchmark runs some functionality a prespecified number of times.
+ */
+trait Bench extends Benchmark {
+ val size: Int
+
+ val parallelism: Int
+
+ val runWhat: String
+
+ /**
+ * Name of the benchmark. Convention is for it to start with the name of the collection being
+ * tested, continuing '.' and ending with the name of the specific functionality being benchmarked.
+ * @return
+ */
+ def name: String = companion.fullname
+ def collectionName: String = companion.collectionName
+ def benchName: String = companion.benchName
+
+ def companion: BenchCompanion
+
+ def runseq: Unit
+
+ def runpar: Unit
+
+ /**
+ * Describes the number of runs of the test.
+ */
+ val runs = 10
+
+ /**
+ * Returns the number of repetitions for this benchmark.
+ */
+ def repetitionsPerRun = 500
+
+ /**
+ * Resets the benchmark object. Typically, this means recreating
+ * the collection being tested.
+ */
+ def reset: Unit
+
+ /**
+ * Returns a map of available comparison tests.
+ */
+ def comparisons: List[String] = companion.comparisons
+
+ def comparison(name: String): Option[() => Unit] = comparisonMap.get(name)
+
+ def comparisonMap: Map[String, () => Unit]
+
+ def run = runWhat match {
+ case "seq" => for (i <- 0 until repetitionsPerRun) runseq
+ case "par" => for (i <- 0 until repetitionsPerRun) runpar
+ case _ => comparison(runWhat) match {
+ case Some(fun) => for (i <- 0 until repetitionsPerRun) fun()
+ case None => throw new IllegalArgumentException("Unknown bench option: `" + runWhat +
+ "`, need `seq`, `par` or one of: " + comparisons.mkString("`", "`, `", "`"))
+ }
+ }
+
+ /**
+ * Prints results of the benchmark. May be overidden in benchmarks.
+ */
+ def printResults {}
+
+ def executeBenchmark = {
+ println("-----------------------")
+ print(name + ", " + runWhat + ", par.=" + parallelism + ", sz=" + niceSize + ": ")
+
+ val times = runBenchmark(runs)
+
+ for (t <- times) print(t + " ")
+ println
+ printResults
+ }
+
+ private def niceSize = if (size < 1000 || size % 1000 != 0) size.toString else size / 1000 + "k"
+}
+
+
+trait HavingResult[T] extends Bench {
+ var runresult: T = null.asInstanceOf[T]
+
+ abstract override def printResults {
+ println("result: " + (if (runresult != null) runresult else "<not set>"))
+ super.printResults
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Arrays.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Arrays.scala
new file mode 100644
index 0000000000..fd3b4aab08
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Arrays.scala
@@ -0,0 +1,63 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+
+
+
+
+
+object Arrays {
+
+ @inline def genericApply[T](xs: Array[T], idx: Int): T = xs.asInstanceOf[AnyRef] match {
+ case x: Array[AnyRef] => x(idx).asInstanceOf[T]
+ case _ => genericApplyNotAnyRef(xs, idx)
+ }
+
+ @noinline private def genericApplyNotAnyRef[T](xs: Array[T], idx: Int): T = xs.asInstanceOf[AnyRef] match {
+ case x: Array[Int] => x(idx).asInstanceOf[T]
+ case x: Array[Double] => x(idx).asInstanceOf[T]
+ case x: Array[Long] => x(idx).asInstanceOf[T]
+ case x: Array[Float] => x(idx).asInstanceOf[T]
+ case x: Array[Char] => x(idx).asInstanceOf[T]
+ case x: Array[Byte] => x(idx).asInstanceOf[T]
+ case x: Array[Short] => x(idx).asInstanceOf[T]
+ case x: Array[Boolean] => x(idx).asInstanceOf[T]
+ case x: Array[Unit] => x(idx).asInstanceOf[T]
+ case null => throw new NullPointerException
+ }
+
+ @inline def apply(xs: AnyRef, idx: Int): Any = xs match {
+ case x: Array[AnyRef] => x(idx).asInstanceOf[Any]
+ case _ => applyNotAnyRef(xs, idx)
+ }
+
+ @noinline private def applyNotAnyRef(xs: AnyRef, idx: Int): Any = xs match {
+ case x: Array[Int] => x(idx).asInstanceOf[Any]
+ case x: Array[Double] => x(idx).asInstanceOf[Any]
+ case x: Array[Long] => x(idx).asInstanceOf[Any]
+ case x: Array[Float] => x(idx).asInstanceOf[Any]
+ case x: Array[Char] => x(idx).asInstanceOf[Any]
+ case x: Array[Byte] => x(idx).asInstanceOf[Any]
+ case x: Array[Short] => x(idx).asInstanceOf[Any]
+ case x: Array[Boolean] => x(idx).asInstanceOf[Any]
+ case x: Array[Unit] => x(idx).asInstanceOf[Any]
+ case null => throw new NullPointerException
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Dummy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Dummy.scala
new file mode 100644
index 0000000000..56af7b9d85
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Dummy.scala
@@ -0,0 +1,22 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+
+
+case class Dummy(in: Int) {
+ def op = {}
+}
+
+object Dummy {
+ def dummyOp(a: Int) = { if (a < 0) -1 }
+ def dummyOp(d: Dummy) = { if (d.in < 0) d.op }
+}
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/IntAccess.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/IntAccess.scala
new file mode 100644
index 0000000000..948ecb419e
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/IntAccess.scala
@@ -0,0 +1,68 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+import scala.collection.parallel.benchmarks._
+
+
+
+object IntAccess extends BenchCompanion {
+ def collectionName = "array";
+ def benchName = "access-int";
+ def apply(sz: Int, p: Int, what: String) = new IntAccess(sz, p, what)
+ override def comparisons = List("any", "cast", "manif", "unknown")
+ override def defaultSize = 100000
+}
+
+
+class IntAccess(sz: Int, p: Int, what: String)
+extends Resetting(n => n, sz, p, what) with UnknownManif[Int] {
+ def companion = IntAccess
+
+ def runseq {}
+ def runpar {}
+
+ def runany = {
+ var i = 0
+ while (i < sz) {
+ val d = anyarray(i).asInstanceOf[Int]
+ i += 1
+ }
+ }
+
+ def runcast = {
+ var i = 0
+ while (i < sz) {
+ val d = Arrays.apply(castarray, i).asInstanceOf[Int]
+ i += 1
+ }
+ }
+
+ def runmanif = {
+ var i = 0
+ while (i < sz) {
+ val d = manifarray(i)
+ if (op(d)) i += 1
+ i += 1
+ }
+ }
+
+ def op(a: Int) = a < 0
+
+ def comparisonMap = collection.Map("any" -> runany _, "cast" -> runcast _,
+ "manif" -> runmanif _, "unknown" -> rununknown _)
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/ObjectAccess.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/ObjectAccess.scala
new file mode 100644
index 0000000000..3cc38f1b58
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/ObjectAccess.scala
@@ -0,0 +1,75 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+import scala.collection.parallel.benchmarks._
+
+
+
+object ObjectAccess extends BenchCompanion {
+ def collectionName = "array";
+ def benchName = "access-obj";
+ def apply(sz: Int, p: Int, what: String) = new ObjectAccess(sz, p, what)
+ override def comparisons = List("any", "cast", "gencast", "manif", "unknown")
+ override def defaultSize = 100000
+}
+
+
+class ObjectAccess(sz: Int, p: Int, what: String)
+extends Resetting(Dummy(_), sz, p, what) with UnknownManif[Dummy] {
+ def companion = ObjectAccess
+
+ def runseq {}
+ def runpar {}
+
+ def runany = {
+ var i = 0
+ while (i < sz) {
+ val d = anyarray(i).asInstanceOf[Dummy]
+ Dummy.dummyOp(d)
+ i += 1
+ }
+ }
+
+ def runcast = {
+ var i = 0
+ while (i < sz) {
+ val d = Arrays.apply(castarray, i).asInstanceOf[Dummy]
+ i += 1
+ }
+ }
+
+ def rungenericcast = {
+ var i = 0
+ while (i < sz) {
+ val d = Arrays.genericApply(gencastarray, i)
+ i += 1
+ }
+ }
+
+ def runmanif = {
+ var i = 0
+ while (i < sz) {
+ val d = manifarray(i)
+ if (d.in < 0) i += 1
+ i += 1
+ }
+ }
+
+ def comparisonMap = collection.Map("any" -> runany _, "cast" -> runcast _, "gencast" -> rungenericcast _,
+ "manif" -> runmanif _, "unknown" -> rununknown _)
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala
new file mode 100644
index 0000000000..9e6102fb94
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala
@@ -0,0 +1,39 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+import scala.collection.parallel.benchmarks._
+
+
+abstract class Resetting[T: Manifest](elemcreate: Int => T, sz: Int, p: Int, what: String)
+extends Bench {
+ val size = sz
+ val parallelism = p
+ val runWhat = what
+
+ var anyarray: Array[Any] = null
+ var castarray: AnyRef = null
+ var gencastarray: Array[T] = null
+ var manifarray: Array[T] = null
+
+ reset
+
+ def reset = what match {
+ case "any" =>
+ anyarray = new Array[Any](sz)
+ for (i <- 0 until sz) anyarray(i) = elemcreate(i)
+ case "cast" =>
+ val arr = new Array[T](sz)
+ for (i <- 0 until sz) arr(i) = elemcreate(i)
+ castarray = arr
+ case "gencast" =>
+ gencastarray = new Array[T](sz)
+ for (i <- 0 until sz) gencastarray(i) = elemcreate(i)
+ case "manif" =>
+ manifarray = new Array[T](sz)
+ for (i <- 0 until sz) manifarray(i) = elemcreate(i)
+ case "unknown" =>
+ manifarray = new Array[T](sz)
+ for (i <- 0 until sz) manifarray(i) = elemcreate(i)
+ case _ =>
+ }
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/UnknownManif.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/UnknownManif.scala
new file mode 100644
index 0000000000..d7196c0277
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/UnknownManif.scala
@@ -0,0 +1,38 @@
+package scala.collection.parallel.benchmarks.arrays
+
+
+
+
+trait UnknownManif[T] {
+ def manifarray: Array[T]
+ def size: Int
+
+ def rununknown {
+ val arr = manifarray
+ val sz = size
+ var i = 0
+ while (i < sz) {
+ val d = arr(i)
+ op(d)
+ i += 1
+ }
+ }
+
+ def op(d: Any) {}
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala
new file mode 100644
index 0000000000..3699b1a255
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala
@@ -0,0 +1,58 @@
+package scala.collection.parallel.benchmarks.generic
+
+
+
+
+class Dummy(val in: Int) {
+ var num = in
+ override def toString = in.toString
+}
+
+
+object DummyOperators extends Operators[Dummy] {
+ val reducer = (a: Dummy, b: Dummy) => {
+ var i = 0
+ if (a.in > b.in) {
+ a.num = a.in + b.in + i
+ a
+ } else {
+ b.num = a.in + b.in + i
+ b
+ }
+ }
+ private def rec(a: Int, b: Int): Int = {
+ val result = if (b == 0) a else {
+ rec(b, a - b * (a / b))
+ }
+ result + 1000
+ }
+ val mediumreducer = (a: Dummy, b: Dummy) => {
+ var i = 0
+ var sum = a.num + b.num
+ b.num = rec(a.num, b.num)
+ b
+ }
+ val filterer = (a: Dummy) => {
+ a.in % 2 == 0
+ }
+ val mapper = (a: Dummy) => {
+ a.num = a.in % 2
+ a
+ }
+ val heavymapper = (a: Dummy) => {
+ var i = -100
+ while (i < 0) {
+ if (a.in < i) a.num += 1
+ i += 1
+ }
+ a
+ }
+ val taker = (a: Dummy) => {
+ a.in >= 0
+ }
+}
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala
new file mode 100644
index 0000000000..42399c980a
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala
@@ -0,0 +1,51 @@
+package scala.collection.parallel.benchmarks.generic
+
+
+
+
+
+
+trait Operators[T] {
+
+ def reducer: (T, T) => T
+ def mediumreducer: (T, T) => T
+ def filterer: T => Boolean
+ def mapper: T => T
+ def heavymapper: T => T
+ def taker: T => Boolean
+
+}
+
+
+
+trait IntOperators extends Operators[Int] {
+
+ val reducer: (Int, Int) => Int = _ + _
+ val mediumreducer: (Int, Int) => Int = (a: Int, b: Int) => {
+ val result = if (b == 0) a else {
+ mediumreducer.apply(b, a - b * (a / b))
+ }
+ result + 1000
+ }
+ val filterer: Int => Boolean = _ % 2 == 0
+ val mapper: Int => Int = _ * 2
+ val heavymapper: Int => Int = (n: Int) => {
+ var i = -10
+ var sum = 0
+ while (i < 0) {
+ sum += -i
+ i += 1
+ }
+ n + sum
+ }
+ val taker: Int => Boolean = _ < 10000
+
+}
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala
new file mode 100644
index 0000000000..4e81cacd4d
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala
@@ -0,0 +1,213 @@
+package scala.collection.parallel
+package benchmarks
+package generic
+
+
+
+
+
+
+
+trait ParallelIterableBench[T, Coll <: ParallelIterable[T]] extends collection.parallel.benchmarks.Bench {
+ self =>
+
+ protected var seqcoll: Iterable[T] = null
+ protected var parcoll: Coll = null.asInstanceOf[Coll]
+
+ reset
+
+ def reset = runWhat match {
+ case "seq" => this.seqcoll = createSequential(size, parallelism)
+ case "par" => this.parcoll = createParallel(size, parallelism)
+ case _ =>
+ }
+
+ def nameOfCollection: String
+ def operators: Operators[T]
+ def createSequential(sz: Int, p: Int): Iterable[T]
+ def createParallel(sz: Int, p: Int): Coll
+
+ trait IterableBenchCompanion extends BenchCompanion {
+ def collectionName = self.nameOfCollection
+ }
+
+ trait IterableBench extends ParallelIterableBench[T, Coll] {
+ def nameOfCollection = self.nameOfCollection
+ def operators = self.operators
+ def createSequential(sz: Int, p: Int) = self.createSequential(size, parallelism)
+ def createParallel(sz: Int, p: Int) = self.createParallel(size, parallelism)
+ def forkJoinPool: scala.concurrent.forkjoin.ForkJoinPool = self.forkJoinPool
+ }
+
+ def forkJoinPool: scala.concurrent.forkjoin.ForkJoinPool
+
+ override def printResults {
+ println(" --- Fork join pool state --- ")
+ println("Parallelism: " + forkJoinPool.getParallelism)
+ println("Active threads: " + forkJoinPool.getActiveThreadCount)
+ println("Work stealings: " + forkJoinPool.getStealCount)
+ }
+
+}
+
+
+trait ParallelSeqBench[T, Coll <: ParallelSeq[T]] extends ParallelIterableBench[T, Coll] {
+ self =>
+
+ def createSequential(sz: Int, p: Int): Seq[T]
+
+ trait SeqBenchCompanion extends BenchCompanion {
+ def collectionName = self.nameOfCollection
+ }
+
+ trait SeqBench extends IterableBench with ParallelSeqBench[T, Coll] {
+ override def createSequential(sz: Int, p: Int) = self.createSequential(size, parallelism)
+ }
+
+}
+
+
+trait NotBenchmark {
+ lazy val runWhat = "";
+ val size = -1
+ val parallelism = -1
+ def runpar {}
+ def runseq {}
+ def companion = throw new UnsupportedOperationException
+}
+
+
+/**
+ * Standard benchmarks for collections.
+ */
+trait StandardParallelIterableBench[T, Coll <: ParallelIterable[T]] extends ParallelIterableBench[T, Coll] {
+
+ object Reduce extends IterableBenchCompanion {
+ override def defaultSize = 50000
+ def benchName = "reduce";
+ def apply(sz: Int, p: Int, w: String) = new Reduce(sz, p, w)
+ }
+
+ class Reduce(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[T, Coll] {
+ def comparisonMap = collection.Map()
+ def runseq = this.seqcoll.reduceLeft(operators.reducer)
+ def runpar = this.parcoll.reduce(operators.reducer)
+ def companion = Reduce
+ }
+
+ object ReduceMedium extends IterableBenchCompanion {
+ override def defaultSize = 5000
+ def benchName = "reduce-medium";
+ def apply(sz: Int, p: Int, w: String) = new ReduceMedium(sz, p, w)
+ }
+
+ class ReduceMedium(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[T, Coll] {
+ def comparisonMap = collection.Map()
+ def runseq = this.seqcoll.reduceLeft(operators.mediumreducer)
+ def runpar = this.parcoll.reduce(operators.mediumreducer)
+ def companion = ReduceMedium
+ }
+
+}
+
+
+
+/**
+ * Benchmarks for sequence views.
+ */
+trait ParallelSeqViewBench[T, Coll <: ParallelSeqView[T, ParallelSeq[T], CollSeq], CollSeq] extends ParallelSeqBench[T, Coll] {
+
+ object Reduce extends IterableBenchCompanion {
+ override def defaultSize = 50000
+ def benchName = "reduce";
+ def apply(sz: Int, p: Int, w: String) = new Reduce(sz, p, w)
+ }
+
+ class Reduce(val size: Int, val parallelism: Int, val runWhat: String)
+ extends SeqBench with ParallelSeqViewBench[T, Coll, CollSeq] {
+ def comparisonMap = collection.Map()
+ def runseq = this.seqcoll.reduceLeft(operators.reducer)
+ def runpar = this.parcoll.reduce(operators.reducer)
+ def companion = Reduce
+ }
+
+ object MediumReduce extends IterableBenchCompanion {
+ override def defaultSize = 50000
+ def benchName = "reduce-medium";
+ def apply(sz: Int, p: Int, w: String) = new MediumReduce(sz, p, w)
+ }
+
+ class MediumReduce(val size: Int, val parallelism: Int, val runWhat: String)
+ extends SeqBench with ParallelSeqViewBench[T, Coll, CollSeq] {
+ def comparisonMap = collection.Map()
+ def runseq = this.seqcoll.reduceLeft(operators.mediumreducer)
+ def runpar = this.parcoll.reduce(operators.mediumreducer)
+ def companion = Reduce
+ }
+
+ object ModifyThenReduce extends SeqBenchCompanion {
+ override def defaultSize = 20000
+ def benchName = "modify-then-reduce";
+ def apply(sz: Int, p: Int, w: String) = new ModifyThenReduce(sz, p, w)
+ }
+
+ class ModifyThenReduce(val size: Int, val parallelism: Int, val runWhat: String)
+ extends SeqBench with ParallelSeqViewBench[T, Coll, CollSeq] {
+ val toadd = createSequential(size, parallelism)
+ def comparisonMap = collection.Map()
+ def runseq = {
+ val modified = (seqcoll ++ toadd).drop(size).map(operators.mapper).++(toadd).take(size)
+ modified.reduceLeft(operators.reducer)
+ }
+ def runpar = {
+ val modified = (parcoll ++ toadd).drop(size).map(operators.mapper).++(toadd).take(size)
+ modified.reduce(operators.reducer)
+ }
+ def companion = ModifyThenReduce
+ }
+
+ object ModifyThenForce extends SeqBenchCompanion {
+ override def defaultSize = 20000
+ def benchName = "modify-then-force";
+ def apply(sz: Int, p: Int, w: String) = new ModifyThenForce(sz, p, w)
+ }
+
+ class ModifyThenForce(val size: Int, val parallelism: Int, val runWhat: String)
+ extends SeqBench with ParallelSeqViewBench[T, Coll, CollSeq] {
+ val toadd = createSequential(size, parallelism)
+ def comparisonMap = collection.Map()
+ def runseq = (seqcoll ++ toadd).drop(size).map(operators.mapper).++(toadd).take(size)
+ def runpar = {
+ val r: ParallelSeqView[T, ParallelSeq[T], Seq[T]] = (parcoll ++ toadd).drop(size).map(operators.mapper).++(toadd).take(size)
+ r.force
+ }
+ def companion = ModifyThenForce
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala
new file mode 100644
index 0000000000..7c15df1fe2
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala
@@ -0,0 +1,54 @@
+package scala.collection.parallel.benchmarks
+package hashtries
+
+
+
+
+import collection.immutable.{HashMap => HashTrie}
+import collection.mutable.HashMap
+
+
+
+
+
+
+class Construct(val size: Int, val parallelism: Int, val runWhat: String) extends Bench {
+ def reset {}
+
+ def runpar = throw new UnsupportedOperationException
+ def runseq = throw new UnsupportedOperationException
+ def runhashmap = {
+ val hashmap = new HashMap[Int, Int]
+ for (i <- 0 until size) hashmap += ((i, i))
+ }
+ def runhashtrie = {
+ var hashtrie = new HashTrie[Int, Int]
+ for (i <- 0 until size) hashtrie += ((i, i))
+ }
+
+ def companion = Construct
+ def comparisonMap = Map("hashmap" -> runhashmap _, "hashtrie" -> runhashtrie _)
+}
+
+
+object Construct extends BenchCompanion {
+ def collectionName = "HashTrie"
+ def benchName = "construct";
+ def apply(sz: Int, p: Int, what: String) = new Construct(sz, p, what)
+ override def defaultSize = 5000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Foreach.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Foreach.scala
new file mode 100644
index 0000000000..6002b5d8b8
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Foreach.scala
@@ -0,0 +1,45 @@
+package scala.collection.parallel.benchmarks
+package hashtries
+
+
+
+
+import collection.immutable.{HashMap => HashTrie}
+import collection.mutable.HashMap
+
+
+
+
+
+
+class Foreach(val size: Int, val parallelism: Int, val runWhat: String) extends Bench with IntInit {
+ def runpar = throw new UnsupportedOperationException
+ def runseq = throw new UnsupportedOperationException
+ def runhashmap = hashmap.foreach(n => ())
+ def runhashtrie = hashtrie.foreach(n => ())
+ def companion = Foreach
+ def comparisonMap = Map("hashmap" -> runhashmap _, "hashtrie" -> runhashtrie _)
+}
+
+
+object Foreach extends BenchCompanion {
+ def collectionName = "HashTrie"
+ def benchName = "foreach-light";
+ def apply(sz: Int, p: Int, what: String) = new Foreach(sz, p, what)
+ override def defaultSize = 25000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/IntInit.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/IntInit.scala
new file mode 100644
index 0000000000..3328dcbe0f
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/IntInit.scala
@@ -0,0 +1,30 @@
+package scala.collection.parallel.benchmarks
+package hashtries
+
+
+
+
+import collection.immutable.{HashMap => HashTrie}
+import collection.mutable.HashMap
+
+
+
+trait IntInit extends Bench {
+ var hashmap: HashMap[Int, Int] = null
+ var hashtrie: HashTrie[Int, Int] = null
+
+ reset
+ def reset = runWhat match {
+ case "hashmap" => initHashMap
+ case "hashtrie" => initHashTrie
+ }
+ def initHashTrie = {
+ hashtrie = new HashTrie
+ for (i <- 0 until size) hashtrie += ((i, i))
+ }
+ def initHashMap = {
+ hashmap = new HashMap
+ for (i <- 0 until size) hashmap += ((i, i))
+ }
+
+} \ No newline at end of file
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala
new file mode 100644
index 0000000000..d27aa200b8
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala
@@ -0,0 +1,51 @@
+package scala.collection.parallel.benchmarks
+package hashtries
+
+
+
+
+import collection.immutable.{HashMap => HashTrie}
+import collection.mutable.HashMap
+
+
+
+
+
+
+class Iterate(val size: Int, val parallelism: Int, val runWhat: String) extends Bench with IntInit {
+ def runpar = throw new UnsupportedOperationException
+ def runseq = throw new UnsupportedOperationException
+ def runhashmap = {
+ val it = hashmap.iterator
+ while (it.hasNext) it.next
+ }
+ def runhashtrie = {
+ val it = hashtrie.iterator
+ while (it.hasNext) it.next
+ }
+ def companion = Iterate
+ def comparisonMap = Map("hashmap" -> runhashmap _, "hashtrie" -> runhashtrie _)
+}
+
+
+object Iterate extends BenchCompanion {
+ def collectionName = "HashTrie"
+ def benchName = "iterate-light";
+ def apply(sz: Int, p: Int, what: String) = new Iterate(sz, p, what)
+ override def defaultSize = 25000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Lookup.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Lookup.scala
new file mode 100644
index 0000000000..4ee8c17118
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Lookup.scala
@@ -0,0 +1,57 @@
+package scala.collection.parallel.benchmarks
+package hashtries
+
+
+
+
+import collection.immutable.{HashMap => HashTrie}
+import collection.mutable.HashMap
+
+
+
+
+
+
+class Lookup(val size: Int, val parallelism: Int, val runWhat: String) extends Bench with IntInit {
+ def runpar = throw new UnsupportedOperationException
+ def runseq = throw new UnsupportedOperationException
+ def runhashmap = {
+ var i = 0
+ while (i < size) {
+ hashmap(i)
+ i += 1
+ }
+ }
+ def runhashtrie = {
+ var i = 0
+ while (i < size) {
+ hashtrie(i)
+ i += 1
+ }
+ }
+ def companion = Iterate
+ def comparisonMap = Map("hashmap" -> runhashmap _, "hashtrie" -> runhashtrie _)
+}
+
+
+object Lookup extends BenchCompanion {
+ def collectionName = "HashTrie"
+ def benchName = "lookup";
+ def apply(sz: Int, p: Int, what: String) = new Lookup(sz, p, what)
+ override def defaultSize = 25000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/AggregateLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/AggregateLight.scala
new file mode 100644
index 0000000000..540c7550c7
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/AggregateLight.scala
@@ -0,0 +1,39 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+import scala.collection.parallel.mutable.ParallelArray
+import extra166y.{ParallelArray => JSR166Array}
+
+
+object AggregateLight extends Companion {
+ def benchName = "aggregate-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new AggregateLight(sz, parallelism, what)
+ override def comparisons = List()
+ override def defaultSize = 200000
+
+ val seqop = (a: Cont, b: Cont) => b
+ val combop = (a: Cont, b: Cont) => a
+}
+
+
+class AggregateLight(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = AggregateLight
+ override def repetitionsPerRun = 350
+ override val runs = 20
+
+ def runpar = pa.aggregate(new Cont(0))(companion.seqop, companion.combop)
+ def runseq = sequentialReduce(companion.seqop, sz, new Cont(0))
+ override def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Companion.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Companion.scala
new file mode 100644
index 0000000000..744351a39b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Companion.scala
@@ -0,0 +1,9 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+trait Companion extends BenchCompanion {
+ def collectionName = "ParallelArray"
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CopyToArray.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CopyToArray.scala
new file mode 100644
index 0000000000..0f743eeb96
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CopyToArray.scala
@@ -0,0 +1,21 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object CopyToArray extends Companion {
+ def benchName = "copytoarray";
+ def apply(sz: Int, parallelism: Int, what: String) = new CopyToArray(sz, parallelism, what)
+ override def comparisons = List()
+ override def defaultSize = 200000
+}
+
+class CopyToArray(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = CopyToArray
+ val destarr = new Array[Any](sz)
+
+ def runpar = pa.copyToArray(destarr, 0, sz)
+ def runseq = sequentialCopyToArray(destarr, 0, sz)
+ def comparisonMap = collection.Map()
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Corresponds.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Corresponds.scala
new file mode 100644
index 0000000000..2e461460a8
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Corresponds.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class Corresponds(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Boolean] {
+ def companion = Corresponds
+ override def repetitionsPerRun = 400
+
+ val same = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p
+ }
+
+ def runpar = runresult = pa.corresponds(same)(corr)
+ def runseq = runresult = sequentialCorresponds(same, corr, sz)
+ override def comparisonMap = collection.Map()
+
+ val corr = (a: Cont, b: Cont) => a.in == b.in
+}
+
+object Corresponds extends Companion {
+ def benchName = "corresponds";
+ def apply(sz: Int, p: Int, what: String) = new Corresponds(sz, p, what)
+ override def comparisons = List()
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountHeavy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountHeavy.scala
new file mode 100644
index 0000000000..722d721288
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountHeavy.scala
@@ -0,0 +1,36 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object CountHeavy extends Companion {
+ def benchName = "count-heavy";
+ def apply(sz: Int, parallelism: Int, what: String) = new CountHeavy(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 16
+
+ val pred = (a: Cont) => heavyCheck(a)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = heavyCheck(a)
+ }
+
+ def heavyCheck(a: Cont) = {
+ val n = a.in
+ (n until (n + 200)).map(checkPrime(_)).reduceLeft(_ && _)
+ }
+ def checkPrime(n: Int) = {
+ var isPrime = true
+ for (i <- 2 until (scala.math.sqrt(n).toInt + 1)) if (n % i == 0) isPrime = false
+ isPrime
+ }
+}
+
+class CountHeavy(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = CountHeavy
+
+ def runpar = pa.count(CountHeavy.pred)
+ def runseq = sequentialCount(CountHeavy.pred, sz)
+ def runjsr = jsrarr.withFilter(CountHeavy.predjsr).size
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountLight.scala
new file mode 100644
index 0000000000..87eb07452f
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountLight.scala
@@ -0,0 +1,21 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object CountLight extends Companion {
+ def benchName = "count-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new CountLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+}
+
+class CountLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = CountLight
+
+ def runpar = pa.count(Cont.pred)
+ def runseq = sequentialCount(Cont.pred, sz)
+ def runjsr = jsrarr.withFilter(Cont.predjsr).size
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountList.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountList.scala
new file mode 100644
index 0000000000..0d9550d2bd
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/CountList.scala
@@ -0,0 +1,30 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object CountList extends Companion {
+ def benchName = "count-list";
+ def apply(sz: Int, parallelism: Int, what: String) = new CountList(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 1000
+
+ val listCreator = (i: Int) => (0 until (i % 50 + 50)).toList
+ val pred = (lst: List[Int]) => check(lst)
+ val predjsr = new extra166y.Ops.Predicate[List[Int]] {
+ def op(lst: List[Int]) = check(lst)
+ }
+
+ def check(lst: List[Int]) = lst.foldLeft(0)((sum, n) => sum + n * n) % 2 == 0
+}
+
+class CountList(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, CountList.listCreator, new Array[Any](_), classOf[List[Int]]) {
+ def companion = CountList
+ override def repetitionsPerRun = 250
+
+ def runpar = pa.count(CountList.pred)
+ def runseq = sequentialCount(CountList.pred, sz)
+ def runjsr = jsrarr.withFilter(CountList.predjsr).size
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DiffHalf.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DiffHalf.scala
new file mode 100644
index 0000000000..3d4221d945
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DiffHalf.scala
@@ -0,0 +1,48 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class DiffHalf(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = DiffHalf
+ override def repetitionsPerRun = 400
+
+ val similar = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p.drop(p.size / 2)
+ }
+
+ def runpar = runresult = pa.diff(similar).size
+ def runseq = runresult = sequentialDiff(similar, sz).size
+ override def comparisonMap = collection.Map()
+
+ val corr = (a: Cont, b: Cont) => a.in == b.in
+}
+
+object DiffHalf extends Companion {
+ def benchName = "diff-half";
+ def apply(sz: Int, p: Int, what: String) = new DiffHalf(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 10000
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DropMany.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DropMany.scala
new file mode 100644
index 0000000000..d80ba91a29
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/DropMany.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object DropMany extends Companion {
+ def benchName = "drop-many";
+ def apply(sz: Int, parallelism: Int, what: String) = new DropMany(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 50000
+}
+
+class DropMany(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = DropMany
+ override def repetitionsPerRun = 400
+ runresult = -1
+
+ def runpar = runresult = pa.drop(pa.size / 2).size
+ def runseq = runresult = sequentialDrop(sz / 2, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ExistsLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ExistsLight.scala
new file mode 100644
index 0000000000..401ab38e0b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ExistsLight.scala
@@ -0,0 +1,49 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object ExistsLight extends Companion {
+ def benchName = "exists-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new ExistsLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+
+ val pred = (a: Cont) => a.in < 0
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in < 0
+ }
+}
+
+class ExistsLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Boolean] {
+ def companion = ExistsLight
+ runresult = false
+
+ def runpar = runresult = pa.exists(ExistsLight.pred)
+ def runseq = runresult = sequentialExists(ExistsLight.pred, sz)
+ def runjsr = runresult = jsrarr.withFilter(ExistsLight.predjsr).size > 0
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FilterLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FilterLight.scala
new file mode 100644
index 0000000000..ee6545efbf
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FilterLight.scala
@@ -0,0 +1,64 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object FilterLight extends Companion {
+ def benchName = "filter-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new FilterLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 10000
+
+ val pred = (a: Cont) => check(a.in)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = check(a.in)
+ }
+
+ def check(n: Int) = {
+ var res = n
+// var i = 1
+// while (i < 10) {
+// res += n % i
+// i += 1
+// }
+ res % 2 == 0
+ }
+}
+
+class FilterLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = FilterLight
+ override def repetitionsPerRun = 250
+ override val runs = 30
+ runresult = -1
+
+ def runpar = runresult = pa.filter(FilterLight.pred).size
+ def runseq = runresult = sequentialFilter(FilterLight.pred, sz).size
+ def runjsr = runresult = { jsrarr.withFilter(FilterLight.predjsr).all.size }
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FindLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FindLight.scala
new file mode 100644
index 0000000000..11cb6c69fd
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FindLight.scala
@@ -0,0 +1,52 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object FindLight extends Companion {
+ def benchName = "find-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new FindLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+
+ val pred = (a: Cont) => a.in < -10
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in < -10
+ }
+}
+
+class FindLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Option[Cont]] {
+ def companion = FindLight
+ runresult = None
+
+ def runpar = runresult = pa.find(FindLight.pred)
+ def runseq = runresult = sequentialFind(FindLight.pred, sz)
+ def runjsr = runresult = { jsrarr.withFilter(FindLight.predjsr).size > 0; None }
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FlatMapLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FlatMapLight.scala
new file mode 100644
index 0000000000..b1f8942d94
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/FlatMapLight.scala
@@ -0,0 +1,24 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+
+
+object FlatMapLight extends Companion {
+ def benchName = "flatmap-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new FlatMapLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 10000
+
+ def fun = (a: Cont) => { List(1, 2, 3, 4, a.in) }
+}
+
+class FlatMapLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = FlatMapLight
+
+ def runpar = pa.flatMap(FlatMapLight.fun)
+ def runseq = sequentialFlatMap(FlatMapLight.fun, sz)
+ def comparisonMap = collection.Map()
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallHeavy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallHeavy.scala
new file mode 100644
index 0000000000..c354f65ec9
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallHeavy.scala
@@ -0,0 +1,59 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object ForallHeavy extends Companion {
+ def benchName = "forall-heavy";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForallHeavy(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 16
+
+ val pred = (a: Cont) => heavyCheck(a)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = heavyCheck(a)
+ }
+
+ def heavyCheck(a: Cont) = {
+ val init = a.in + 1
+ var cnt = init
+ var i = 0
+ while (i < 10000) {
+ cnt = -2 * cnt
+ cnt /= 2
+ i += 1
+ }
+ cnt += init * 5 + 10
+ cnt >= 0
+ }
+}
+
+class ForallHeavy(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ForallHeavy
+
+ def runpar = pa.forall(ForallHeavy.pred)
+ def runseq = sequentialForall(ForallHeavy.pred, sz)
+ def runjsr = jsrarr.withFilter(ForallHeavy.predjsr).size == sz
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallLight.scala
new file mode 100644
index 0000000000..079f2ccc32
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallLight.scala
@@ -0,0 +1,46 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object ForallLight extends Companion {
+ def benchName = "forall-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForallLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+
+ val pred = (a: Cont) => a.in >= 0
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in >= 0
+ }
+}
+
+class ForallLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ForallLight
+
+ def runpar = pa.forall(ForallLight.pred)
+ def runseq = sequentialForall(ForallLight.pred, sz)
+ def runjsr = jsrarr.withFilter(ForallLight.predjsr).size == sz
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallQuickStop.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallQuickStop.scala
new file mode 100644
index 0000000000..310105dd41
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallQuickStop.scala
@@ -0,0 +1,46 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object ForallQuickStop extends Companion {
+ def benchName = "forall-quickstop";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForallQuickStop(sz, parallelism, what)
+ override def defaultSize = 200000
+
+ val pred = (a: Cont) => a.in != 50
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in != 50
+ }
+}
+
+class ForallQuickStop(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Boolean] {
+ def companion = ForallQuickStop
+
+ def runpar = runresult = pa.forall(ForallQuickStop.pred)
+ def runseq = runresult = sequentialForall(ForallQuickStop.pred, sz)
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallStop80k.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallStop80k.scala
new file mode 100644
index 0000000000..cbfa6ebb42
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForallStop80k.scala
@@ -0,0 +1,46 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object ForallStop80k extends Companion {
+ def benchName = "forall-stop80k";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForallStop80k(sz, parallelism, what)
+ override def defaultSize = 100000
+
+ val pred = (a: Cont) => a.in != 80000
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in != 80000
+ }
+}
+
+class ForallStop80k(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Boolean] {
+ def companion = ForallStop80k
+
+ def runpar = runresult = pa.forall(ForallStop80k.pred)
+ def runseq = runresult = sequentialForall(ForallStop80k.pred, sz)
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachHeavy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachHeavy.scala
new file mode 100644
index 0000000000..17ad2f9882
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachHeavy.scala
@@ -0,0 +1,42 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object ForeachHeavy extends Companion {
+ def benchName = "foreach-heavy";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForeachHeavy(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 16
+
+ val fun = (a: Cont) => heavyOperation(a)
+ val funjsr = new extra166y.Ops.Procedure[Cont] {
+ def op(a: Cont) = heavyOperation(a)
+ }
+
+ def heavyOperation(a: Cont) {
+ checkPrime(a.in + 1000000000)
+ }
+
+ def checkPrime(n: Int) = {
+ var isPrime = true
+ var i = 2
+ val until = scala.math.sqrt(n).toInt + 1
+ while (i < until) {
+ if (n % i == 0) isPrime = false
+ i += 1
+ }
+ isPrime
+ }
+}
+
+class ForeachHeavy(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ForeachHeavy
+ override def repetitionsPerRun = 250
+
+ def runpar = pa.foreach(ForeachHeavy.fun)
+ def runseq = sequentialForeach(ForeachHeavy.fun, sz)
+ def runjsr = jsrarr.apply(ForeachHeavy.funjsr)
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachLight.scala
new file mode 100644
index 0000000000..79901148ac
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ForeachLight.scala
@@ -0,0 +1,26 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object ForeachLight extends Companion {
+ def benchName = "foreach-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new ForeachLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+
+ val fun = (a: Cont) => a.num = a.in
+ val funjsr = new extra166y.Ops.Procedure[Cont] {
+ def op(a: Cont) = a.num = a.in
+ }
+}
+
+class ForeachLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ForeachLight
+
+ def runpar = pa.foreach(ForeachLight.fun)
+ def runseq = sequentialForeach(ForeachLight.fun, sz)
+ def runjsr = jsrarr.apply(ForeachLight.funjsr)
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IndexWhere.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IndexWhere.scala
new file mode 100644
index 0000000000..e8a74286ae
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IndexWhere.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class IndexWhere(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = IndexWhere
+ override def repetitionsPerRun = 400
+
+ def runpar = runresult = pa.indexWhere(IndexWhere.pred2, 0)
+ def runseq = runresult = sequentialIndexWhere(IndexWhere.pred2, 0, sz)
+ override def comparisonMap = collection.Map()
+}
+
+object IndexWhere extends Companion {
+ def benchName = "index-where";
+ def apply(sz: Int, p: Int, what: String) = new IndexWhere(sz, p, what)
+ override def comparisons = List()
+
+ val pred = (c: Cont) => {
+ var in = c.in
+ var i = 2
+ while (i < 5) {
+ if (in % i == 0) in = 0
+ i += 1
+ }
+ c.in >= 0 && in == -1
+ }
+ val pred2 = (c: Cont) => c.in == 280000
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IntersectHalf.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IntersectHalf.scala
new file mode 100644
index 0000000000..4d71bf8590
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/IntersectHalf.scala
@@ -0,0 +1,48 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class IntersectHalf(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = IntersectHalf
+ override def repetitionsPerRun = 400
+
+ val similar = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p.drop(p.size / 2)
+ }
+
+ def runpar = runresult = pa.intersect(similar).size
+ def runseq = runresult = sequentialIntersect(similar, sz).size
+ override def comparisonMap = collection.Map()
+
+ val corr = (a: Cont, b: Cont) => a.in == b.in
+}
+
+object IntersectHalf extends Companion {
+ def benchName = "intersect-half";
+ def apply(sz: Int, p: Int, what: String) = new IntersectHalf(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 10000
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/LastIndexWhere.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/LastIndexWhere.scala
new file mode 100644
index 0000000000..dbba807390
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/LastIndexWhere.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class LastIndexWhere(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = LastIndexWhere
+ override def repetitionsPerRun = 400
+
+ def runpar = runresult = pa.lastIndexWhere(LastIndexWhere.pred2, pa.size - 1)
+ def runseq = runresult = sequentialLastIndexWhere(LastIndexWhere.pred2, sz - 1, sz)
+ override def comparisonMap = collection.Map()
+}
+
+object LastIndexWhere extends Companion {
+ def benchName = "last-index-where";
+ def apply(sz: Int, p: Int, what: String) = new LastIndexWhere(sz, p, what)
+ override def comparisons = List()
+
+ val pred = (c: Cont) => {
+ var in = c.in
+ var i = 2
+ while (i < 5) {
+ if (in % i == 0) in = 0
+ i += 1
+ }
+ c.in >= 0 || in == 0
+ }
+ val pred2 = (c: Cont) => c.in == 500
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MapLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MapLight.scala
new file mode 100644
index 0000000000..f6a5985cb7
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MapLight.scala
@@ -0,0 +1,27 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object MapLight extends Companion {
+ def benchName = "map-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new MapLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 100000
+
+ def fun = (a: Cont) => { a }
+ def funjsr = new extra166y.Ops.Op[Cont, Cont] {
+ def op(a: Cont) = { a }
+ }
+}
+
+class MapLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = MapLight
+
+ def runpar = pa.map(MapLight.fun)
+ def runseq = sequentialMap(MapLight.fun, sz)
+// def runseq = sequentialMapOpt(MapLight.fun, sz)
+ def runjsr = jsrarr.replaceWithMapping(MapLight.funjsr).all
+ def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala
new file mode 100644
index 0000000000..a8bb5ea1ca
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala
@@ -0,0 +1,84 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+import collection.parallel.immutable.ParallelRange
+
+
+object MatrixMultiplication extends Companion {
+ def benchName = "matrix-mult";
+ def apply(sz: Int, parallelism: Int, what: String) = new MatrixMultiplication(sz, parallelism, what)
+ override def comparisons = List()
+ override def defaultSize = 100
+}
+
+class MatrixMultiplication(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = MatrixMultiplication
+
+ val a = Matrix.unit[Int](sz)
+ val b = Matrix.unit[Int](sz)
+ var c = new Matrix[Int](sz)
+
+ def runpar = c = a * b //{ c.assignProduct(a, b) } //; println("--------"); c.output }
+ def runseq = throw new UnsupportedOperationException
+ def comparisonMap = collection.Map()
+
+ class Matrix[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) {
+ val array = new Array[T](n * n)
+
+ def apply(y: Int, x: Int) = array(y * n + x)
+
+ def update(y: Int, x: Int, elem: T) = array(y * n + x) = elem
+
+ def *(b: Matrix[T]) = {
+ val m = new Matrix[T](n)
+ m.assignProduct(this, b)
+ m
+ }
+
+ def assignProduct(a: Matrix[T], b: Matrix[T]) = {
+ val range = new ParallelRange(0, n * n, 1, false)
+ range.environment = forkjoinpool
+ for (i <- range) this(i / n, i % n) = calcProduct(a, b, i / n, i % n);
+ }
+
+ private def calcProduct(a: Matrix[T], b: Matrix[T], y: Int, x: Int): T = {
+ import num._
+ var sum = zero
+ for (i <- 0 until n) sum += a(y, i) * b(i, x)
+ sum
+ }
+
+ def output = for (y <- 0 until n) {
+ for (x <- 0 until n) print(this(y, x))
+ println
+ }
+ }
+
+ object Matrix {
+ def unit[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) = {
+ val m = new Matrix[T](n)
+ for (i <- 0 until n) m(i, i) = num.one
+ m
+ }
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MinLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MinLight.scala
new file mode 100644
index 0000000000..66cd29807a
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MinLight.scala
@@ -0,0 +1,28 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+
+/** Tests reduce method using an operator creating an object as a result. */
+class MinLight(sz: Int, p: Int, what: String)
+extends Resettable[Int](sz, p, what, (i: Int) => i, new Array[Any](_), classOf[Int]) {
+ def companion = MinLight
+ override def repetitionsPerRun = 400
+
+ def runpar = pa.min(Ordering[Int])
+ def runseq = sequentialMin(sz)
+ override def comparisonMap = collection.Map()
+}
+
+object MinLight extends Companion {
+ def benchName = "min-light";
+ def apply(sz: Int, p: Int, what: String) = new MinLight(sz, p, what)
+ override def comparisons = List()
+}
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PadToDouble.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PadToDouble.scala
new file mode 100644
index 0000000000..3bbe99516b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PadToDouble.scala
@@ -0,0 +1,53 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class PadToDouble(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = PadToDouble
+ override def repetitionsPerRun = 400
+
+ val similar = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p.drop(p.size / 2)
+ }
+
+ def runpar = runresult = pa.padTo(size * 2, padder).size
+ def runseq = runresult = sequentialPadTo(size * 2, padder, size).size
+ override def comparisonMap = collection.Map()
+
+ val padder = new Cont(0)
+}
+
+
+object PadToDouble extends Companion {
+ def benchName = "padto-double";
+ def apply(sz: Int, p: Int, what: String) = new PadToDouble(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 25000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartialMapLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartialMapLight.scala
new file mode 100644
index 0000000000..e06720ae37
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartialMapLight.scala
@@ -0,0 +1,24 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object PartialMapLight extends Companion {
+ def benchName = "partmap-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new PartialMapLight(sz, parallelism, what)
+ override def comparisons = List()
+ override def defaultSize = 100000
+
+ def fun: PartialFunction[Cont, Cont] = {
+ case c: Cont if c.in >= 0 => c
+ }
+}
+
+class PartialMapLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = PartialMapLight
+
+ def runpar = pa.collect(PartialMapLight.fun)
+ def runseq = sequentialPartialMap(PartialMapLight.fun, sz)
+ def comparisonMap = collection.Map()
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartitionLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartitionLight.scala
new file mode 100644
index 0000000000..c0fb0454ec
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PartitionLight.scala
@@ -0,0 +1,61 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object PartitionLight extends Companion {
+ def benchName = "partition-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new PartitionLight(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 20000
+
+ val pred = (a: Cont) => check(a.in)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = check(a.in)
+ }
+
+ def check(n: Int) = {
+ var res = n
+ var i = 1
+ while (i < 5) {
+ res += n % i
+ i += 1
+ }
+ (res % 2 == 0) && (res % 312 == 0)
+ }
+}
+
+class PartitionLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = PartitionLight
+ runresult = -1
+
+ def runpar = runresult = pa.partition(PartitionLight.pred)._1.size
+ def runseq = runresult = sequentialPartition(PartitionLight.pred, sz)._1.size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PatchHalf.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PatchHalf.scala
new file mode 100644
index 0000000000..e1fc0f9f2a
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PatchHalf.scala
@@ -0,0 +1,46 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class PatchHalf(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = PatchHalf
+ override def repetitionsPerRun = 400
+
+ val similar = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p.drop(p.size / 2)
+ }
+
+ def runpar = runresult = pa.patch(size / 2, similar, 0).size
+ def runseq = runresult = sequentialPatch(size / 2, similar, 0, size).size
+ override def comparisonMap = collection.Map()
+}
+
+object PatchHalf extends Companion {
+ def benchName = "patch-half";
+ def apply(sz: Int, p: Int, what: String) = new PatchHalf(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 25000
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PlusPlus.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PlusPlus.scala
new file mode 100644
index 0000000000..ca500281e3
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/PlusPlus.scala
@@ -0,0 +1,29 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.mutable.ParallelArray
+
+
+object PlusPlus extends Companion {
+ def benchName = "plusplus";
+ def apply(sz: Int, parallelism: Int, what: String) = new PlusPlus(sz, parallelism, what)
+ override def comparisons = List()
+ override def defaultSize = 50000
+}
+
+class PlusPlus(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = PlusPlus
+
+ val thatarr = new Array[Cont](sz)
+ val thatpa = new ParallelArray[Cont](sz)
+
+ def runpar = pa ++ thatpa
+ def runseq = arr ++ thatarr
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceHeavy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceHeavy.scala
new file mode 100644
index 0000000000..5806dd7831
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceHeavy.scala
@@ -0,0 +1,22 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+class ReduceHeavy(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ReduceHeavy
+ override def repetitionsPerRun = 100
+
+ def runseq = sequentialReduce(Cont.opheavy, sz, new Cont(0))
+ def runpar = pa.reduce(Cont.opheavy)
+ def runjsr = jsrarr.reduce(Cont.reducerheavy, new Cont(0))
+ override def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+object ReduceHeavy extends Companion {
+ def benchName = "reduce-heavy";
+ def apply(sz: Int, p: Int, what: String) = new ReduceHeavy(sz, p, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 16
+}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceLight.scala
new file mode 100644
index 0000000000..890cbf5108
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceLight.scala
@@ -0,0 +1,50 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+import scala.collection.parallel.mutable.ParallelArray
+import extra166y.{ParallelArray => JSR166Array}
+
+
+object ReduceLight extends Companion {
+ def benchName = "reduce-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new ReduceLight(sz, parallelism, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 200000
+}
+
+
+class ReduceLight(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
+ def companion = ReduceLight
+ override def repetitionsPerRun = 350
+ override val runs = 20
+
+ def runpar = {
+ pa.reduce(Cont.op)
+// updatePar
+ }
+
+ def runjsr = {
+ jsrarr.reduce(Cont.reducer, new Cont(0))
+// updateJsr
+ }
+
+ def runseq = {
+ sequentialReduce(Cont.op, sz, new Cont(0))
+// updateSeq
+ }
+
+ override def comparisonMap = collection.Map("jsr" -> runjsr _)
+
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceList.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceList.scala
new file mode 100644
index 0000000000..db4fb3331f
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceList.scala
@@ -0,0 +1,53 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+object ReduceList extends Companion {
+ def benchName = "reduce-list";
+ def apply(sz: Int, p: Int, what: String) = new ReduceList(sz, p, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 20000
+}
+
+object ListCreator extends (Int => List[Int]) {
+ def apply(idx: Int) = {
+ val len = 50 + idx % 100
+ (for (i <- 0 until len) yield i).toList
+ }
+}
+
+object ListOps {
+ val redop = (a: List[Int], b: List[Int]) => combineLists(a, b)
+ val reducer = new extra166y.Ops.Reducer[List[Int]] {
+ def op(a: List[Int], b: List[Int]) = combineLists(a, b)
+ }
+ def combineLists(a: List[Int], b: List[Int]) = {
+ if (a.foldLeft(0)(_ + _) > b.foldLeft(0)(_ + _)) a else b
+ }
+}
+
+class ReduceList(sz: Int, p: Int, what: String)
+extends Resettable[List[Int]](sz, p, what, ListCreator, new Array[Any](_), classOf[List[Int]]) {
+ def companion = ReduceList
+ override def repetitionsPerRun = 10
+ override val runs = 15
+
+ def runpar = pa.reduce(ListOps.redop)
+ def runseq = sequentialReduce(ListOps.redop, sz, List[Int]())
+ def runjsr = jsrarr.reduce(ListOps.reducer, List[Int]())
+ override def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceNew.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceNew.scala
new file mode 100644
index 0000000000..c69f64d329
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceNew.scala
@@ -0,0 +1,30 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+
+/** Tests reduce method using an operator creating an object as a result. */
+class ReduceNew(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i),
+ new Array[Any](_), classOf[Cont]) {
+ def companion = ReduceNew
+ override def repetitionsPerRun = 200
+
+ def runpar = pa.reduce(Cont.opnew)
+ def runseq = sequentialReduce(Cont.opnew, sz, new Cont(0))
+ def runjsr = jsrarr.reduce(Cont.reducernew, new Cont(0))
+ override def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+object ReduceNew extends Companion {
+ def benchName = "reduce-new";
+ def apply(sz: Int, p: Int, what: String) = new ReduceNew(sz, p, what)
+ override def comparisons = List("jsr")
+}
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReducePrime.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReducePrime.scala
new file mode 100644
index 0000000000..b6ff69e37b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReducePrime.scala
@@ -0,0 +1,65 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object IntWrapCreator extends (Int => IntWrap) {
+ def apply(idx: Int) = new IntWrap(shiftaround(idx))
+ def shiftaround(idx: Int) = idx * 40192 + 717
+}
+
+case class IntWrap(val num: Int)
+
+object IntOps {
+ val op = (a: IntWrap, b: IntWrap) => primereduce(a, b)
+ val reducer = new extra166y.Ops.Reducer[IntWrap] {
+ def op(a: IntWrap, b: IntWrap) = primereduce(a, b)
+ }
+
+ def primereduce(a: IntWrap, b: IntWrap) = {
+ val check = (checkPrime(a.num), checkPrime(b.num))
+ if (a.num > b.num) a else b
+ }
+
+ def checkPrime(n: Int) = {
+ var isPrime = true
+ var i = 2
+ val until = scala.math.sqrt(n).toInt + 1
+ while (i < until) {
+ if (n % i == 0) isPrime = false
+ i += 1
+ }
+ isPrime
+ }
+}
+
+class ReducePrime(sz: Int, p: Int, what: String)
+extends Resettable[IntWrap](sz, p, what, IntWrapCreator, new Array[Any](_), classOf[IntWrap])
+with HavingResult[IntWrap] {
+ def companion = ReducePrime
+
+ def runseq = runresult = sequentialReduce(IntOps.op, sz, new IntWrap(0))
+ def runpar = runresult = pa.reduce(IntOps.op)
+ def runjsr = runresult = jsrarr.reduce(IntOps.reducer, new IntWrap(0))
+ override def comparisonMap = collection.Map("jsr" -> runjsr _)
+}
+
+object ReducePrime extends Companion {
+ def benchName = "reduce-prime";
+ def apply(sz: Int, p: Int, what: String) = new ReducePrime(sz, p, what)
+ override def comparisons = List("jsr")
+ override def defaultSize = 100
+}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/RemoveDuplicates.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/RemoveDuplicates.scala
new file mode 100644
index 0000000000..a66d2fb1f8
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/RemoveDuplicates.scala
@@ -0,0 +1,44 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class RemoveDuplicates(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = RemoveDuplicates
+ override def repetitionsPerRun = 400
+
+ def runpar = runresult = pa.distinct.size
+ def runseq = runresult = sequentialRemoveDuplicates(size).size
+ override def comparisonMap = collection.Map()
+}
+
+object RemoveDuplicates extends Companion {
+ def benchName = "remove-duplicates";
+ def apply(sz: Int, p: Int, what: String) = new RemoveDuplicates(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 10000
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Resettable.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Resettable.scala
new file mode 100644
index 0000000000..83168ca979
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Resettable.scala
@@ -0,0 +1,127 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+import scala.collection.parallel.mutable.ParallelArray
+import extra166y.{ParallelArray => JSR166Array}
+
+
+class Cont(val in: Int) {
+ var num = in
+ override def toString = in.toString
+}
+
+object Cont {
+ val pred = (a: Cont) => a.in > 100
+
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = a.in > 100
+ }
+
+ val op = (a: Cont, b: Cont) => {
+ b.num = a.in + b.in
+ b
+ }
+
+ val opnew = (a: Cont, b: Cont) => new Cont(a.in + b.in)
+
+ val opheavy = (a: Cont, b: Cont) => {
+ heavyComputation(a, b)
+ }
+
+ val reducer = new extra166y.Ops.Reducer[Cont] {
+ def op(a: Cont, b: Cont) = {
+ b.num = a.in + b.in
+ b
+ }
+ }
+
+ val reducernew = new extra166y.Ops.Reducer[Cont] {
+ def op(a: Cont, b: Cont) = new Cont(a.in + b.in)
+ }
+
+ val reducerheavy = new extra166y.Ops.Reducer[Cont] {
+ def op(a: Cont, b: Cont) = heavyComputation(a, b)
+ }
+
+ def heavyComputation(a: Cont, b: Cont) = {
+ val f = a.in
+ val s = b.in
+ var i = 0
+ var res = f * s
+ while (i < 50000) {
+ if ((i + f) % 3 == 0) res += s
+ else res -= f
+ i += 1
+ }
+ b.num = res
+ b
+ }
+}
+
+abstract class Resettable[T](val size: Int, val parallelism: Int, val runWhat: String,
+ elemcreator: Int => T, arrcreator: Int => Array[Any], cls: Class[T])
+extends Bench with SequentialOps[T] {
+ val forkjoinpool = new scala.concurrent.forkjoin.ForkJoinPool(parallelism)
+ forkjoinpool.setMaximumPoolSize(parallelism)
+ val papool = new jsr166y.ForkJoinPool(parallelism)
+ papool.setMaximumPoolSize(parallelism)
+
+ var pa: ParallelArray[T] = null
+ var jsrarr: JSR166Array[T] = null
+ reset
+
+ def reset = runWhat match {
+ case "seq" =>
+ arr = arrcreator(size)
+ for (i <- 0 until size) arr(i) = elemcreator(i)
+ case "par" =>
+ pa = new ParallelArray[T](size)
+ pa.environment = forkjoinpool
+ for (i <- 0 until size) pa(i) = elemcreator(i)
+ case "jsr" =>
+ jsrarr = JSR166Array.create(size, cls, papool)
+ for (i <- 0 until size) jsrarr.set(i, elemcreator(i))
+ case _ => throw new IllegalArgumentException("Unknown type: " + runWhat)
+ }
+
+ var updateCounter = 0
+ def incUpdateCounter {
+ updateCounter += 1
+ if (updateCounter > size) updateCounter = 0
+ }
+
+ def updateSeq {
+ val tmp = arr(updateCounter)
+ arr(updateCounter) = arr(size - updateCounter - 1)
+ arr(size - updateCounter - 1) = tmp
+ incUpdateCounter
+ }
+
+ def updatePar {
+ val tmp = pa(updateCounter)
+ pa(updateCounter) = pa(size - updateCounter - 1)
+ pa(size - updateCounter - 1) = tmp
+ incUpdateCounter
+ }
+
+ def updateJsr {
+ val tmp = jsrarr.get(updateCounter)
+ jsrarr.set(updateCounter, jsrarr.get(size - updateCounter - 1))
+ jsrarr.set(size - updateCounter - 1, tmp)
+ incUpdateCounter
+ }
+
+ override def printResults {
+ println(" --- Fork join pool state --- ")
+ println("Parallelism: " + forkjoinpool.getParallelism)
+ println("Active threads: " + forkjoinpool.getActiveThreadCount)
+ println("Work stealings: " + forkjoinpool.getStealCount)
+ }
+}
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Reverse.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Reverse.scala
new file mode 100644
index 0000000000..0d00e60731
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/Reverse.scala
@@ -0,0 +1,35 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class Reverse(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont]) {
+ def companion = Reverse
+ override def repetitionsPerRun = 400
+
+ def runpar = pa.reverse
+ def runseq = sequentialReverse(sz)
+ override def comparisonMap = collection.Map()
+}
+
+object Reverse extends Companion {
+ def benchName = "reverse";
+ def apply(sz: Int, p: Int, what: String) = new Reverse(sz, p, what)
+ override def comparisons = List()
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReverseMap.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReverseMap.scala
new file mode 100644
index 0000000000..c9f4a02baa
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReverseMap.scala
@@ -0,0 +1,48 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class ReverseMap(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont]) {
+ def companion = ReverseMap
+ override def repetitionsPerRun = 100
+
+ def runpar = pa.reverseMap(compl)
+ def runseq = sequentialReverseMap(compl, sz)
+ override def comparisonMap = collection.Map()
+
+ val id = (c: Cont) => c
+ val compl = (c: Cont) => {
+ var in = c.in
+ var i = 2
+ while (i < 6) {
+ if (in % i == 0) in = 0
+ i += 1
+ }
+ if (in < 0) null
+ else c
+ }
+}
+
+object ReverseMap extends Companion {
+ def benchName = "reverse-map";
+ def apply(sz: Int, p: Int, what: String) = new ReverseMap(sz, p, what)
+ override def comparisons = List()
+ override def defaultSize = 100000
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SameElementsLong.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SameElementsLong.scala
new file mode 100644
index 0000000000..54f9519a1b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SameElementsLong.scala
@@ -0,0 +1,45 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class SameElementsLong(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Boolean] {
+ def companion = SameElementsLong
+ override def repetitionsPerRun = 400
+
+ val same = {
+ val p = new collection.parallel.mutable.ParallelArray[Cont](sz)
+ for (i <- 0 until sz) p(i) = what match {
+ case "seq" => arr(i).asInstanceOf[Cont]
+ case "par" => pa(i)
+ }
+ p
+ }
+
+ def runpar = runresult = pa.sameElements(same)
+ def runseq = runresult = sequentialSameElements(same, sz)
+ override def comparisonMap = collection.Map()
+}
+
+object SameElementsLong extends Companion {
+ def benchName = "same-elements-long";
+ def apply(sz: Int, p: Int, what: String) = new SameElementsLong(sz, p, what)
+ override def comparisons = List()
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SegmentLength.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SegmentLength.scala
new file mode 100644
index 0000000000..1f9041c373
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SegmentLength.scala
@@ -0,0 +1,42 @@
+package scala.collection.parallel.benchmarks
+package parallel_array
+
+
+
+
+
+
+
+class SegmentLength(sz: Int, p: Int, what: String)
+extends Resettable[Cont](sz, p, what, (i: Int) => new Cont(i), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SegmentLength
+ override def repetitionsPerRun = 400
+
+ def runpar = runresult = pa.segmentLength(SegmentLength.pred2, 0)
+ def runseq = runresult = sequentialSegmentLength(SegmentLength.pred2, 0, sz)
+ override def comparisonMap = collection.Map()
+}
+
+object SegmentLength extends Companion {
+ def benchName = "segment-length";
+ def apply(sz: Int, p: Int, what: String) = new SegmentLength(sz, p, what)
+ override def comparisons = List()
+
+ val pred = (c: Cont) => {
+ var in = c.in
+ var i = 2
+ while (i < 5) {
+ if (in % i == 0) in = 0
+ i += 1
+ }
+ c.in >= 0 || in == 0
+ }
+ val pred2 = (c: Cont) => c.in >= 0
+}
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SequentialOps.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SequentialOps.scala
new file mode 100644
index 0000000000..36e1d22d7e
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SequentialOps.scala
@@ -0,0 +1,547 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+trait SequentialOps[T] {
+
+ var arr: Array[Any] = null
+
+ def sequentialReduce(op: (T, T) => T, sz: Int, init: T) = {
+ var i = 0
+ val until = sz
+ var sum = init
+ while (i < until) {
+ sum = op(sum, arr(i).asInstanceOf[T])
+ i += 1
+ }
+ sum
+ }
+
+ def sequentialCount(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val until = sz
+ var sum = 0
+ while (i < until) {
+ if (pred(arr(i).asInstanceOf[T])) sum += 1
+ i += 1
+ }
+ sum
+ }
+
+ def sequentialForeach[U](f: T => U, sz: Int) = {
+ var i = 0
+ val until = sz
+ var sum = 0
+ while (i < until) {
+ f(arr(i).asInstanceOf[T])
+ i += 1
+ }
+ }
+
+ def sequentialSum[U >: T](sz: Int)(implicit num: Numeric[U]) = {
+ var i = 0
+ val until = sz
+ var sum = num.zero
+ while (i < until) {
+ sum = num.plus(sum, arr(i).asInstanceOf[T])
+ i += 1
+ }
+ sum
+ }
+
+ def sequentialMin[U >: T](sz: Int)(implicit ord: Ordering[U]) = {
+ var i = 1
+ val until = sz
+ var min = arr(0).asInstanceOf[U]
+ while (i < until) {
+ val elem = arr(i).asInstanceOf[U]
+ if (ord.lt(elem, min)) min = elem
+ i += 1
+ }
+ min
+ }
+
+ def sequentialForall(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val until = sz
+ var all = true
+ while (i < until) {
+ if (pred(arr(i).asInstanceOf[T])) i += 1
+ else {
+ all = false
+ i = until
+ }
+ }
+ all
+ }
+
+ def sequentialExists(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val until = sz
+ var some = false
+ while (i < until) {
+ if (pred(arr(i).asInstanceOf[T])) {
+ some = true
+ i = until
+ } else i += 1
+ }
+ some
+ }
+
+ def sequentialFind(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val until = sz
+ var opt: Option[T] = None
+ while (i < until) {
+ if (pred(arr(i).asInstanceOf[T])) {
+ opt = Some(arr(i).asInstanceOf[T])
+ i = until
+ } else i += 1
+ }
+ opt
+ }
+
+ def sequentialFilter(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val buff = new collection.mutable.ArrayBuffer[T]
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (pred(elem)) buff += elem
+ i += 1
+ }
+ val resarr = new Array[Any](buff.size)
+ buff.copyToArray(resarr, 0)
+ resarr
+ }
+
+ def sequentialPartition(pred: T => Boolean, sz: Int) = {
+ var i = 0
+ val btrue = new collection.mutable.ArrayBuffer[T]
+ val bfalse = new collection.mutable.ArrayBuffer[T]
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (pred(elem)) btrue += elem
+ else bfalse += elem
+ i += 1
+ }
+ val restrue = new Array[Any](btrue.size)
+ val resfalse = new Array[Any](bfalse.size)
+ btrue.copyToArray(restrue, 0)
+ bfalse.copyToArray(resfalse, 0)
+ (restrue, resfalse)
+ }
+
+ def sequentialTakeOpt(n: Int, sz: Int) = {
+ var i = 0
+ val until = if (n < sz) n else sz
+ val res = new Array[Any](until)
+ Array.copy(arr, 0, res, 0, until)
+// while (i < until) {
+// res(i) = arr(i)
+// i += 1
+// }
+ res
+ }
+
+ def sequentialTake(n: Int, sz: Int) = {
+ var i = 0
+ val b = new collection.mutable.ArrayBuffer[T]
+ val until = if (n < sz) n else sz
+ b.sizeHint(until)
+ while (i < until) {
+ val elem = arr(i).asInstanceOf[T]
+ b += elem
+ i += 1
+ }
+ val res = new Array[Any](n)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialDrop(n: Int, sz: Int) = {
+ var i = n
+ val b = new collection.mutable.ArrayBuffer[T]
+ b.sizeHint(sz - n)
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ b += elem
+ i += 1
+ }
+ val res = new Array[Any](n)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialSlice(from: Int, until: Int, sz: Int) = {
+ var i = from
+ val b = new collection.mutable.ArrayBuffer[T]
+ b.sizeHint(until - from)
+ while (i < until) {
+ val elem = arr(i).asInstanceOf[T]
+ b += elem
+ i += 1
+ }
+ val res = new Array[Any](until - from)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialSplitAtOpt(n: Int, sz: Int) = {
+ var i = 0
+ val before = new Array[Any](n)
+ val after = new Array[Any](sz - n)
+ Array.copy(arr, 0, before, 0, n)
+ Array.copy(arr, n, after, 0, sz - n)
+ (before, after)
+ }
+
+ def sequentialSplitAt(n: Int, sz: Int) = {
+ var i = 0
+ val before = new collection.mutable.ArrayBuffer[T]
+ before.sizeHint(n)
+ val after = new collection.mutable.ArrayBuffer[T]
+ after.sizeHint(sz - n)
+ while (i < sz) {
+ if (i < n) before += arr(i).asInstanceOf[T]
+ else after += arr(i).asInstanceOf[T]
+ i += 1
+ }
+ val resbef = new Array[Any](n)
+ val resaft = new Array[Any](sz - n)
+ before.copyToArray(resbef, 0)
+ after.copyToArray(resaft, 0)
+ (resbef, resaft)
+ }
+
+ def sequentialTakeWhile(p: T => Boolean, sz: Int) = {
+ var i = 0
+ val b = new collection.mutable.ArrayBuffer[T]
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (p(elem)) {
+ b += elem
+ i += 1
+ } else i = sz
+ }
+ val res = new Array[Any](sz)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialSpan(p: T => Boolean, sz: Int) = {
+ val bpref = new collection.mutable.ArrayBuffer[T]
+ val brest = new collection.mutable.ArrayBuffer[T]
+ var i = 0
+ var prefix = true
+ var pos = sz
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (prefix) {
+ if (p(elem)) bpref += elem
+ else {
+ pos = i
+ prefix = false
+ brest += elem
+ }
+ } else brest += elem
+ i += 1
+ }
+ val respref = new Array[Any](pos)
+ val resrest = new Array[Any](sz - pos)
+ bpref.copyToArray(respref, 0)
+ brest.copyToArray(resrest, 0)
+ (respref, resrest)
+ }
+
+ def sequentialMap(f: T => T, sz: Int) = {
+ val b = new collection.mutable.ArrayBuffer[T](sz)
+
+ var i = 0
+ while (i < sz) {
+ b += f(arr(i).asInstanceOf[T])
+ i += 1
+ }
+
+ val res = new Array[Any](sz)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialMapOpt(f: T => T, sz: Int) = {
+ val res = new Array[Any](sz)
+
+ var i = 0
+ while (i < sz) {
+ res(i) = f(arr(i).asInstanceOf[T])
+ i += 1
+ }
+
+ res
+ }
+
+ def sequentialPartialMap(f: PartialFunction[T, T], sz: Int) = {
+ val b = new collection.mutable.ArrayBuffer[T](sz)
+
+ var i = 0
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (f.isDefinedAt(elem)) b += f(elem)
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialFlatMap(f: T => Traversable[Int], sz: Int) = {
+ val b = new collection.mutable.ArrayBuffer[Int](sz)
+
+ var i = 0
+ while (i < sz) {
+ val ts = f(arr(i).asInstanceOf[T])
+ for (elem <- ts) b += elem
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialCopyToArray(destarr: Array[Any], pos: Int, sz: Int) = {
+ Array.copy(arr, 0, destarr, pos, sz)
+ }
+
+ def sequentialSegmentLength(pred: T => Boolean, from: Int, sz: Int) = {
+ var i = from
+ var cnt = 0
+
+ while (i < sz) {
+ if (pred(arr(i).asInstanceOf[T])) {
+ cnt += 1
+ i += 1
+ } else i = sz
+ }
+
+ cnt
+ }
+
+ def sequentialIndexWhere(pred: T => Boolean, from: Int, sz: Int) = {
+ var i = from
+ var pos = -1
+
+ while (i < sz) {
+ if (pred(arr(i).asInstanceOf[T])) {
+ pos = i
+ i = sz
+ } else i += 1
+ }
+
+ pos
+ }
+
+ def sequentialLastIndexWhere(pred: T => Boolean, end: Int, sz: Int) = {
+ var i = end
+ var pos = -1
+
+ while (i >= 0) {
+ if (pred(arr(i).asInstanceOf[T])) {
+ pos = i
+ i = -1
+ } else i -= 1
+ }
+
+ pos
+ }
+
+ def sequentialReverse(sz: Int) = {
+ val res = new Array[Any](sz)
+
+ var i = sz - 1
+ var j = 0
+ while (i >= 0) {
+ res(j) = arr(i)
+ i -= 1
+ j += 1
+ }
+ res
+ }
+
+ def sequentialReverseMap(f: T => T, sz: Int) = {
+ val res = new Array[Any](sz)
+
+ var i = sz - 1
+ var j = 0
+ while (i >= 0) {
+ res(j) = f(arr(i).asInstanceOf[T])
+ i -= 1
+ j += 1
+ }
+ res
+ }
+
+ def sequentialSameElements(sq: Seq[T], sz: Int): Boolean = {
+ if (sz != sq.length) false
+ else {
+ var i = 0
+ val jt = sq.iterator
+ while (i < sz) {
+ if (arr(i) == jt.next) i += 1
+ else i = sz + 1
+ }
+ if (i == sz) true
+ else false
+ }
+ }
+
+ def sequentialCorresponds(sq: Seq[T], f: (T, T) => Boolean, sz: Int): Boolean = {
+ if (sz != sq.length) false
+ else {
+ var i = 0
+ val jt = sq.iterator
+ while (i < sz) {
+ if (f(arr(i).asInstanceOf[T], jt.next)) i += 1
+ else i = sz + 1
+ }
+ if (i == sz) true
+ else false
+ }
+ }
+
+ def sequentialDiff(sq: Seq[T], sz: Int) = {
+ val occmap = occurences(sq)
+ val b = new collection.mutable.ArrayBuffer[T]
+
+ var i = 0
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (occmap(elem) == 0) b += elem
+ else occmap(elem) -= 1
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialIntersect(sq: Seq[T], sz: Int) = {
+ val occmap = occurences(sq)
+ val b = new collection.mutable.ArrayBuffer[T]
+
+ var i = 0
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ val num = occmap(elem)
+ if (num > 0) {
+ b += elem
+ occmap(elem) = num - 1
+ }
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ private def occurences(sq: Seq[T]) = {
+ val occmap = new collection.mutable.HashMap[T, Int] { override def default(k: T) = 0 }
+ for (elem <- sq.iterator) occmap(elem) += 1
+ occmap
+ }
+
+ def sequentialRemoveDuplicates(sz: Int) = {
+ val occ = new collection.mutable.HashSet[T]
+ val b = new collection.mutable.ArrayBuffer[T]
+
+ var i = 0
+ while (i < sz) {
+ val elem = arr(i).asInstanceOf[T]
+ if (!occ.contains(elem)) {
+ b += elem
+ occ.add(elem)
+ }
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialPatch(from: Int, p: Seq[T], replaced: Int, sz: Int) = {
+ val b = new collection.mutable.ArrayBuffer[T]
+ b.sizeHint(from + (sz - from - replaced) + p.size)
+
+ var i = 0
+ while (i < from) {
+ b += arr(i).asInstanceOf[T]
+ i += 1
+ }
+
+ val jt = p.iterator
+ while (jt.hasNext) b += jt.next
+
+ val skipto = from + replaced
+ while (i < from + replaced) i += 1
+
+ while (i < sz) {
+ b += arr(i).asInstanceOf[T]
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+ def sequentialPadTo(tosize: Int, elem: T, sz: Int) = {
+ val b = new collection.mutable.ArrayBuffer[T]
+ b.sizeHint(tosize)
+
+ var i = 0
+ while (i < sz) {
+ b += arr(i).asInstanceOf[T]
+ i += 1
+ }
+
+ while (i < tosize) {
+ b += elem
+ i += 1
+ }
+
+ val res = new Array[Any](b.size)
+ b.copyToArray(res, 0)
+ res
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceFew.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceFew.scala
new file mode 100644
index 0000000000..c22ae47400
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceFew.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object SliceFew extends Companion {
+ def benchName = "slice-few";
+ def apply(sz: Int, parallelism: Int, what: String) = new SliceFew(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 50000
+}
+
+class SliceFew(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SliceFew
+ override def repetitionsPerRun = 200
+ runresult = -1
+
+ def runpar = runresult = pa.slice(5, 25).size
+ def runseq = runresult = sequentialSlice(5, 25, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMany.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMany.scala
new file mode 100644
index 0000000000..37ad666d93
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMany.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object SliceMany extends Companion {
+ def benchName = "slice-many";
+ def apply(sz: Int, parallelism: Int, what: String) = new SliceMany(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 50000
+}
+
+class SliceMany(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SliceMany
+ override def repetitionsPerRun = 200
+ runresult = -1
+
+ def runpar = runresult = pa.slice(pa.size / 4, pa.size * 3 / 4).size
+ def runseq = runresult = sequentialSlice(sz / 4, sz * 3 / 4, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMedium.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMedium.scala
new file mode 100644
index 0000000000..7da94a4a20
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SliceMedium.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object SliceMedium extends Companion {
+ def benchName = "slice-medium";
+ def apply(sz: Int, parallelism: Int, what: String) = new SliceMedium(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 50000
+}
+
+class SliceMedium(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SliceMedium
+ override def repetitionsPerRun = 200
+ runresult = -1
+
+ def runpar = runresult = pa.slice(pa.size / 7, pa.size * 4 / 7).size
+ def runseq = runresult = sequentialSlice(sz / 7, sz * 4 / 7, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SpanLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SpanLight.scala
new file mode 100644
index 0000000000..4d8b128e1f
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SpanLight.scala
@@ -0,0 +1,62 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object SpanLight extends Companion {
+ def benchName = "span-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new SpanLight(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 20000
+
+ val pred = (a: Cont) => check(a.in)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = check(a.in)
+ }
+
+ def check(n: Int) = {
+ var res = n
+ var i = 1
+ while (i < 10) {
+ res += n % i
+ i += 1
+ }
+ if (n != 10000) res % 2 == 0 || n != 10000
+ else false
+ }
+}
+
+class SpanLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SpanLight
+ runresult = -1
+
+ def runpar = runresult = pa.span(SpanLight.pred)._1.size
+ def runseq = runresult = sequentialSpan(SpanLight.pred, sz)._1.size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SplitHalf.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SplitHalf.scala
new file mode 100644
index 0000000000..d671e56c3d
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SplitHalf.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object SplitHalf extends Companion {
+ def benchName = "split-half";
+ def apply(sz: Int, parallelism: Int, what: String) = new SplitHalf(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 50000
+}
+
+class SplitHalf(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = SplitHalf
+ override def repetitionsPerRun = 300
+ runresult = -1
+
+ def runpar = runresult = pa.splitAt(pa.size / 2)._1.size
+ def runseq = runresult = sequentialSplitAtOpt(sz / 2, sz)._1.size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SumLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SumLight.scala
new file mode 100644
index 0000000000..67ac1c6478
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/SumLight.scala
@@ -0,0 +1,28 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+
+
+
+/** Tests reduce method using an operator creating an object as a result. */
+class SumLight(sz: Int, p: Int, what: String)
+extends Resettable[Int](sz, p, what, (i: Int) => i, new Array[Any](_), classOf[Int]) {
+ def companion = SumLight
+ override def repetitionsPerRun = 500
+
+ def runpar = pa.sum
+ def runseq = sequentialSum(sz)
+ override def comparisonMap = collection.Map()
+}
+
+object SumLight extends Companion {
+ def benchName = "sum-light";
+ def apply(sz: Int, p: Int, what: String) = new SumLight(sz, p, what)
+ override def comparisons = List()
+}
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeMany.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeMany.scala
new file mode 100644
index 0000000000..2f735c1e45
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeMany.scala
@@ -0,0 +1,47 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object TakeMany extends Companion {
+ def benchName = "take-many";
+ def apply(sz: Int, parallelism: Int, what: String) = new TakeMany(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 250000
+}
+
+class TakeMany(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = TakeMany
+ override def repetitionsPerRun = 400
+ runresult = -1
+
+ def runpar = runresult = pa.take(pa.size / 2).size
+ def runseq = runresult = sequentialTake(sz / 2, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeWhileLight.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeWhileLight.scala
new file mode 100644
index 0000000000..255cb695d7
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/TakeWhileLight.scala
@@ -0,0 +1,61 @@
+package scala.collection.parallel.benchmarks.parallel_array
+
+
+import scala.collection.parallel.benchmarks._
+
+
+object TakeWhileLight extends Companion {
+ def benchName = "takewhile-light";
+ def apply(sz: Int, parallelism: Int, what: String) = new TakeWhileLight(sz, parallelism, what)
+ override def comparisons = Nil
+ override def defaultSize = 10000
+
+ val pred = (a: Cont) => check(a.in)
+ val predjsr = new extra166y.Ops.Predicate[Cont] {
+ def op(a: Cont) = check(a.in)
+ }
+
+ def check(n: Int) = {
+ var res = n
+ var i = 1
+ while (i < 10) {
+ res += n % i
+ i += 1
+ }
+ res % 2 == 0 || n > 0
+ }
+}
+
+class TakeWhileLight(sz: Int, p: Int, what: String)
+extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont])
+with HavingResult[Int] {
+ def companion = TakeWhileLight
+ runresult = -1
+
+ def runpar = runresult = pa.takeWhile(TakeWhileLight.pred).size
+ def runseq = runresult = sequentialTakeWhile(TakeWhileLight.pred, sz).size
+ def comparisonMap = collection.Map()
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_range/RangeBenches.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_range/RangeBenches.scala
new file mode 100644
index 0000000000..ccc0568b2b
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_range/RangeBenches.scala
@@ -0,0 +1,208 @@
+package scala.collection.parallel.benchmarks.parallel_range
+
+
+
+
+
+import scala.collection.parallel.benchmarks.generic._
+import scala.collection.parallel.immutable.ParallelRange
+
+
+
+
+
+
+object RangeBenches extends StandardParallelIterableBench[Int, ParallelRange] with NotBenchmark {
+
+ def nameOfCollection = "ParallelRange"
+ def operators = new IntOperators {}
+ def comparisonMap = collection.Map()
+ val forkJoinPool = new scala.concurrent.forkjoin.ForkJoinPool
+ def createSequential(sz: Int, p: Int) = new collection.immutable.Range(0, sz, 1)
+ def createParallel(sz: Int, p: Int) = {
+ val pr = new collection.parallel.immutable.ParallelRange(0, sz, 1, false)
+ forkJoinPool.setParallelism(p)
+ pr.environment = forkJoinPool
+ pr
+ }
+
+ object MapLight extends IterableBenchCompanion {
+ override def defaultSize = 20000
+ def benchName = "map-light";
+ def apply(sz: Int, p: Int, w: String) = new MapLight(sz, p, w)
+ }
+
+ class MapLight(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ def calc(n: Int) = n % 2 + 1
+
+ def comparisonMap = collection.Map()
+ def runseq = for (n <- this.seqcoll) yield calc(n)
+ def runpar = for (n <- this.parcoll) yield calc(n)
+ def companion = MapLight
+ }
+
+ object MapMedium extends IterableBenchCompanion {
+ override def defaultSize = 5000
+ def benchName = "map-medium";
+ def apply(sz: Int, p: Int, w: String) = new MapMedium(sz, p, w)
+ }
+
+ class MapMedium(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ def calc(n: Int) = {
+ var i = 0
+ var sum = n
+ while (i < 40) {
+ i += 1
+ sum += n % i
+ }
+ sum
+ }
+
+ def comparisonMap = collection.Map()
+ def runseq = for (n <- this.seqcoll) yield calc(n)
+ def runpar = for (n <- this.parcoll) yield calc(n)
+ def companion = MapMedium
+ }
+
+ object ForeachModify extends IterableBenchCompanion {
+ override def defaultSize = 150000
+ def benchName = "foreach-modify";
+ def apply(sz: Int, p: Int, w: String) = new ForeachModify(sz, p, w)
+ }
+
+ class ForeachModify(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ val array = new Array[Int](size)
+ def modify(n: Int) = array(n) += 1
+
+ def comparisonMap = collection.Map()
+ def runseq = for (n <- this.seqcoll) modify(n)
+ def runpar = for (n <- this.parcoll) modify(n)
+ def companion = ForeachModify
+ }
+
+ object ForeachModifyMedium extends IterableBenchCompanion {
+ override def defaultSize = 20000
+ def benchName = "foreach-modify-medium";
+ def apply(sz: Int, p: Int, w: String) = new ForeachModifyMedium(sz, p, w)
+ }
+
+ class ForeachModifyMedium(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ val array = new Array[Int](size)
+ def modify(n: Int) = array(n) = {
+ var i = 0
+ var sum = 0
+ while (i < 15) {
+ sum += i % 3
+ i += i + 1
+ }
+ sum
+ }
+
+ def comparisonMap = collection.Map()
+ def runseq = for (n <- this.seqcoll) modify(n)
+ def runpar = for (n <- this.parcoll) modify(n)
+ def companion = ForeachModifyMedium
+ }
+
+ object ForeachModifyHeavy extends IterableBenchCompanion {
+ override def defaultSize = 1000
+ def benchName = "foreach-modify-heavy";
+ def apply(sz: Int, p: Int, w: String) = new ForeachModifyHeavy(sz, p, w)
+ }
+
+ class ForeachModifyHeavy(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ val array = new Array[Int](size)
+ def modify(n: Int) = array(n) = collatz(10000 + array(n))
+
+ def comparisonMap = collection.Map()
+ def runseq = for (n <- this.seqcoll) modify(n)
+ def runpar = for (n <- this.parcoll) modify(n)
+ def companion = ForeachModifyHeavy
+ }
+
+ object ForeachAdd extends IterableBenchCompanion {
+ override def defaultSize = 10000
+ def benchName = "foreach-add";
+ def apply(sz: Int, p: Int, w: String) = new ForeachAdd(sz, p, w)
+ override def comparisons = List("seq-hashmap")
+ }
+
+ class ForeachAdd(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ val cmap = new java.util.concurrent.ConcurrentHashMap[Int, Int]
+ val hmap = new java.util.HashMap[Int, Int]
+
+ override def reset = runWhat match {
+ case "seq-hashmap" => seqcoll = createSequential(size, parallelism)
+ case _ => super.reset
+ }
+
+ def comparisonMap = collection.Map("seq-hashmap" -> runseqhashmap _)
+ def runseqhashmap = for (i <- seqcoll) hmap put (i, onesum(i))
+ def runseq = for (i <- seqcoll) cmap put (i, onesum(i))
+ def runpar = for (i <- parcoll) cmap put (i, onesum(i))
+ def companion = ForeachAdd
+ }
+
+ object ForeachAddCollatz extends IterableBenchCompanion {
+ override def defaultSize = 5000
+ def benchName = "foreach-add-collatz";
+ def apply(sz: Int, p: Int, w: String) = new ForeachAddCollatz(sz, p, w)
+ override def comparisons = List("seq-hashmap")
+ }
+
+ class ForeachAddCollatz(val size: Int, val parallelism: Int, val runWhat: String)
+ extends IterableBench with StandardParallelIterableBench[Int, ParallelRange] {
+ val cmap = new java.util.concurrent.ConcurrentHashMap[Int, Int]
+ val hmap = new java.util.HashMap[Int, Int]
+
+ override def reset = runWhat match {
+ case "seq-hashmap" => seqcoll = createSequential(size, parallelism)
+ case _ => super.reset
+ }
+
+ def comparisonMap = collection.Map("seq-hashmap" -> runseqhashmap _)
+ def runseqhashmap = for (i <- seqcoll) hmap put (i, collatz(i))
+ def runseq = for (i <- seqcoll) cmap put (i, collatz(i))
+ def runpar = for (i <- parcoll) cmap put (i, collatz(i))
+ def companion = ForeachAddCollatz
+ }
+
+ def collatz(n: Int) = {
+ var curr = n
+ var sum = 0
+ while (curr > 1) {
+ sum += curr
+ if (curr % 2 == 0) curr = curr / 2
+ else curr = curr * 3 + 1
+ }
+ sum
+ }
+
+ def onesum(n: Int) = {
+ var left = n
+ var sum = 0
+ while (left > 0) {
+ sum += left % 2
+ left /= 2
+ }
+ sum
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_view/SeqViewBenches.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_view/SeqViewBenches.scala
new file mode 100644
index 0000000000..f174dec7db
--- /dev/null
+++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_view/SeqViewBenches.scala
@@ -0,0 +1,50 @@
+package scala.collection.parallel
+package benchmarks.parallel_view
+
+
+
+import scala.collection.parallel.benchmarks.generic._
+import scala.collection.SeqView
+
+
+
+
+
+
+
+
+
+
+trait DummyViewBenches
+extends ParallelSeqViewBench[Dummy, ParallelSeqView[Dummy, ParallelSeq[Dummy], Seq[Dummy]], Seq[Dummy]] {
+ def nameOfCollection = "ParallelView"
+ def operators = DummyOperators
+ def comparisonMap = collection.Map()
+ val forkJoinPool = new scala.concurrent.forkjoin.ForkJoinPool
+ def createSequential(sz: Int, p: Int) = {
+ val s = new Array[Dummy](sz)
+ for (i <- 0 until sz) s(i) = new Dummy(i)
+ s
+ }
+ def createParallel(sz: Int, p: Int) = {
+ val pa = new collection.parallel.mutable.ParallelArray[Dummy](sz)
+ forkJoinPool.setParallelism(p)
+ for (i <- 0 until sz) pa(i) = new Dummy(i)
+ val v = pa.view
+ v.environment = forkJoinPool
+ v
+ }
+}
+
+
+object DummyViewBenchList extends DummyViewBenches with NotBenchmark
+
+
+
+
+
+
+
+
+
+