diff options
Diffstat (limited to 'test/benchmarks/src/scala/collection/parallel/benchmarks/generic')
3 files changed, 0 insertions, 509 deletions
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala deleted file mode 100644 index 3b5308f8c2..0000000000 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Dummy.scala +++ /dev/null @@ -1,83 +0,0 @@ -package scala.collection.parallel.benchmarks.generic - - - - -class Dummy(val in: Int) { - var num = in - override def toString = in.toString - override def hashCode = in - def dummy = num + in - def one = "1".length -} - - -object DummyOperators extends Operators[Dummy] { - val foreachFun = (a: Dummy) => { - a - () - } - 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.dummy + a.num + a.in + a.one - a - } - override val mapper2 = (a: Dummy) => { - val x = 1 - new Dummy(a.in * -2 + x) - } - val heavymapper = (a: Dummy) => { - var i = -100 - while (i < 0) { - if (a.in < i) a.num += 1 - i += 1 - } - a - } - val flatmapper = (a: Dummy) => { - List(a, a, a, a, a) - } - val taker = (a: Dummy) => { - a.in >= 0 - } - val eachFun: Dummy => Unit = (d: Dummy) => { - d.dummy - } - override val eachPairFun: ((Dummy, Dummy)) => Unit = p => { - p._1.dummy - p._2.dummy - } - override def sequence(sz: Int): Seq[Dummy] = { - val pa = new collection.parallel.mutable.ParArray[Dummy](sz) - for (i <- 0 until sz) pa(i) = new Dummy(i) - pa - } -} - - - - diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala deleted file mode 100644 index 539e3f6972..0000000000 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/Operators.scala +++ /dev/null @@ -1,64 +0,0 @@ -package scala.collection.parallel.benchmarks.generic - - - - - - -trait Operators[T] { - - def foreachFun: T => Unit - def reducer: (T, T) => T - def mediumreducer: (T, T) => T - def filterer: T => Boolean - def mapper: T => T - def mapper2: T => T = error("unsupported") - def heavymapper: T => T - def flatmapper: T => Seq[T] - def taker: T => Boolean - def eachFun: T => Unit - def eachPairFun: ((T, T)) => Unit = error("unsupported") - def sequence(sz: Int): Seq[T] = error("unsupported") - -} - - - -trait IntOperators extends Operators[Int] { - - val foreachFun: Int => Unit = x => () - 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 flatmapper: Int => Seq[Int] = (n: Int) => { - List(n, n, n, n, n) - } - val taker: Int => Boolean = _ < 10000 - val eachFun: Int => Unit = { n => - n % 2 == 0 - } - -} - - - - - - - - diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala deleted file mode 100644 index c39c384927..0000000000 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala +++ /dev/null @@ -1,362 +0,0 @@ -package scala.collection.parallel -package benchmarks -package generic - - - -import scala.collection.SeqView - - - -trait ParIterableBenches[T, Coll <: ParIterable[T]] { -self => - - def createSequential(sz: Int, p: Int): Iterable[T] - def createParallel(sz: Int, p: Int): Coll - def nameOfCollection: String - def operators: Operators[T] - - trait IterableBenchCompanion extends BenchCompanion { - def collectionName = self.nameOfCollection - } - - trait IterableBench extends collection.parallel.benchmarks.Bench { - 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 = 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 - - override def printResults { - println(" --- Fork join pool state --- ") - println("Parallelism: " + forkJoinPool.getParallelism) - println("Active threads: " + forkJoinPool.getActiveThreadCount) - println("Work stealings: " + forkJoinPool.getStealCount) - } - - } - - def forkJoinPool: scala.concurrent.forkjoin.ForkJoinPool - -} - - -trait ParSeqBenches[T, Coll <: ParSeq[T]] extends ParIterableBenches[T, Coll] { -self => - - def createSequential(sz: Int, p: Int): Seq[T] - - trait SeqBenchCompanion extends BenchCompanion { - def collectionName = self.nameOfCollection - } - - trait SeqBench extends IterableBench { - def seqcollAsSeq = seqcoll.asInstanceOf[Seq[T]] - override def createSequential(sz: Int, p: Int) = self.createSequential(sz, p) - } - -} - - - - -/** Standard benchmarks for collections. - */ -trait StandardParIterableBenches[T, Coll <: ParIterable[T]] extends ParIterableBenches[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 { - 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 { - def comparisonMap = collection.Map() - def runseq = this.seqcoll.reduceLeft(operators.mediumreducer) - def runpar = this.parcoll.reduce(operators.mediumreducer) - def companion = ReduceMedium - } - - object Map extends IterableBenchCompanion { - override def defaultSize = 5000 - def benchName = "map"; - def apply(sz: Int, p: Int, w: String) = new Map(sz, p, w) - } - - class Map(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench { - def comparisonMap = collection.Map() - def runseq = this.seqcoll.map(operators.mapper) - def runpar = this.parcoll.map(operators.mapper) - def companion = Map - } - - object Filter extends IterableBenchCompanion { - override def defaultSize = 5000 - def benchName = "filter"; - def apply(sz: Int, p: Int, w: String) = new Filter(sz, p, w) - } - - class Filter(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench { - def comparisonMap = collection.Map() - def runseq = this.seqcoll.filter(operators.filterer) - def runpar = this.parcoll.filter(operators.filterer) - def companion = Filter - } - - object FlatMap extends IterableBenchCompanion { - override def defaultSize = 5000 - def benchName = "flatmap"; - def apply(sz: Int, p: Int, w: String) = new FlatMap(sz, p, w) - } - - class FlatMap(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench { - def comparisonMap = collection.Map() - def runseq = this.seqcoll.flatMap(operators.flatmapper) - def runpar = this.parcoll.flatMap(operators.flatmapper) - def companion = FlatMap - } - -} - - - -/** Benchmarks for sequence views. - */ -trait ParSeqViewBenches[T, Coll <: ParSeqView[T, ParSeq[T], CollSeq], CollSeq] extends ParSeqBenches[T, Coll] { -self => - - trait SeqViewBench extends SeqBench { - lazy val seqview: SeqView[T, Seq[T]] = createSeqView(size, parallelism) - - def createSeqView(sz: Int, p: Int) = self.createSeqView(sz, p) - } - - def createSeqView(sz: Int, p: Int): SeqView[T, Seq[T]] - - object Iteration extends SeqBenchCompanion { - override def defaultSize = 250000 - def benchName = "iter" - def apply(sz: Int, p: Int, w: String) = new Iteration(sz, p, w) - } - - class Iteration(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = this.seqcoll.foreach(operators.eachFun) - def runpar = this.parcoll.pforeach(operators.eachFun) - def runseqview = { - this.seqview.foreach(operators.eachFun) - } - def companion = Iteration - } - - object IterationS extends SeqBenchCompanion { - override def defaultSize = 250000 - def benchName = "iter-s" - def apply(sz: Int, p: Int, w: String) = new IterationS(sz, p, w) - } - - class IterationS(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = this.seqcoll.slice(0, size / 2).foreach(operators.eachFun) - def runpar = this.parcoll.slice(0, size / 2).pforeach(operators.eachFun) - def runseqview = this.seqview.slice(0, size / 2).foreach(operators.eachFun) - def companion = IterationS - } - - object IterationM extends SeqBenchCompanion { - override def defaultSize = 100000 - def benchName = "iter-m" - def apply(sz: Int, p: Int, w: String) = new IterationM(sz, p, w) - } - - class IterationM(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = this.seqcoll.map(operators.mapper).foreach(operators.eachFun) - def runpar = this.parcoll.map(operators.mapper).pforeach(operators.eachFun) - def runseqview = this.seqview.map(operators.mapper).foreach(operators.eachFun) - def companion = IterationM - } - - object IterationA extends SeqBenchCompanion { - override def defaultSize = 50000 - def benchName = "iter-a" - def apply(sz: Int, p: Int, w: String) = new IterationA(sz, p, w) - } - - class IterationA(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - val appended = operators.sequence(size) - val sqappended = appended.toSeq - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = { - val withapp = this.seqcoll.++(sqappended) - withapp.foreach(operators.eachFun) - } - def runpar = this.parcoll.++(appended).pforeach(operators.eachFun) - def runseqview = this.seqview.++(appended).foreach(operators.eachFun) - def companion = IterationA - } - - object IterationZ extends SeqBenchCompanion { - override def defaultSize = 50000 - def benchName = "iter-z" - def apply(sz: Int, p: Int, w: String) = new IterationZ(sz, p, w) - } - - class IterationZ(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - val zipped = operators.sequence(size) - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = { - val withzip = this.seqcoll.zip(zipped) - withzip.foreach(operators.eachPairFun) - } - def runpar = this.parcoll.zip(zipped).pforeach(operators.eachPairFun) - def runseqview = this.seqview.zip(zipped).foreach(operators.eachPairFun) - def companion = IterationZ - } - - object IterationP extends SeqBenchCompanion { - override def defaultSize = 50000 - def benchName = "iter-p" - def apply(sz: Int, p: Int, w: String) = new IterationP(sz, p, w) - } - - class IterationP(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with SeqViewBench { - val patch = operators.sequence(size / 4) - val sqpatch = patch.toSeq - def comparisonMap = collection.Map("seqview" -> runseqview _) - def runseq = { - val withpatch = this.seqcollAsSeq.patch(size / 4, sqpatch, size / 2) - withpatch.foreach(operators.eachFun) - } - def runpar = this.parcoll.patch(size / 4, patch, size / 2).pforeach(operators.eachFun) - def runseqview = this.seqview.patch(size / 4, patch, size / 2).foreach(operators.eachFun) - def companion = IterationP - } - - object Reduce extends SeqBenchCompanion { - 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 SeqViewBench { - def comparisonMap = collection.Map() - def runseq = this.seqcoll.reduceLeft(operators.reducer) - def runpar = this.parcoll.reduce(operators.reducer) - def companion = Reduce - } - - object MediumReduce extends SeqBenchCompanion { - 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 SeqViewBench { - 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 SeqViewBench { - 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 SeqViewBench { - 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: ParSeqView[T, ParSeq[T], Seq[T]] = (parcoll ++ toadd).drop(size).map(operators.mapper).++(toadd).take(size) - r.force - } - def companion = ModifyThenForce - } - -} - - - - - - - - - - - - - - - - - - - - - - - - |