diff options
Diffstat (limited to 'test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala')
-rw-r--r-- | test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala | 167 |
1 files changed, 117 insertions, 50 deletions
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala index da5a2a63ca..fd4e87ab4c 100644 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala +++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/generic/ParallelBenches.scala @@ -4,55 +4,56 @@ package generic +import scala.collection.SeqView - -trait ParIterableBench[T, Coll <: ParIterable[T]] extends collection.parallel.benchmarks.Bench { +trait ParIterableBenches[T, Coll <: ParIterable[T]] { 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 + def nameOfCollection: String + def operators: Operators[T] trait IterableBenchCompanion extends BenchCompanion { def collectionName = self.nameOfCollection } - trait IterableBench extends ParIterableBench[T, Coll] { + 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 - } - 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) + } - 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 ParSeqBench[T, Coll <: ParSeq[T]] extends ParIterableBench[T, Coll] { - self => +trait ParSeqBenches[T, Coll <: ParSeq[T]] extends ParIterableBenches[T, Coll] { +self => def createSequential(sz: Int, p: Int): Seq[T] @@ -60,27 +61,18 @@ trait ParSeqBench[T, Coll <: ParSeq[T]] extends ParIterableBench[T, Coll] { def collectionName = self.nameOfCollection } - trait SeqBench extends IterableBench with ParSeqBench[T, Coll] { - override def createSequential(sz: Int, p: Int) = self.createSequential(size, parallelism) + trait SeqBench extends IterableBench { + override def createSequential(sz: Int, p: Int) = self.createSequential(sz, p) } } -trait NotBenchmark { - lazy val runWhat = ""; - val size = -1 - val parallelism = -1 - def runpar {} - def runseq {} - def companion = throw new UnsupportedOperationException -} -/** - * Standard benchmarks for collections. +/** Standard benchmarks for collections. */ -trait StandardParIterableBench[T, Coll <: ParIterable[T]] extends ParIterableBench[T, Coll] { +trait StandardParIterableBenches[T, Coll <: ParIterable[T]] extends ParIterableBenches[T, Coll] { object Reduce extends IterableBenchCompanion { override def defaultSize = 50000 @@ -89,7 +81,7 @@ trait StandardParIterableBench[T, Coll <: ParIterable[T]] extends ParIterableBen } class Reduce(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench with StandardParIterableBench[T, Coll] { + extends IterableBench { def comparisonMap = collection.Map() def runseq = this.seqcoll.reduceLeft(operators.reducer) def runpar = this.parcoll.reduce(operators.reducer) @@ -103,7 +95,7 @@ trait StandardParIterableBench[T, Coll <: ParIterable[T]] extends ParIterableBen } class ReduceMedium(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench with StandardParIterableBench[T, Coll] { + extends IterableBench { def comparisonMap = collection.Map() def runseq = this.seqcoll.reduceLeft(operators.mediumreducer) def runpar = this.parcoll.reduce(operators.mediumreducer) @@ -117,7 +109,7 @@ trait StandardParIterableBench[T, Coll <: ParIterable[T]] extends ParIterableBen } class Map(val size: Int, val parallelism: Int, val runWhat: String) - extends IterableBench with StandardParIterableBench[T, Coll] { + extends IterableBench { def comparisonMap = collection.Map() def runseq = this.seqcoll.map(operators.mapper) def runpar = this.parcoll.map(operators.mapper) @@ -128,33 +120,108 @@ trait StandardParIterableBench[T, Coll <: ParIterable[T]] extends ParIterableBen -/** - * Benchmarks for sequence views. +/** Benchmarks for sequence views. */ -trait ParSeqViewBench[T, Coll <: ParSeqView[T, ParSeq[T], CollSeq], CollSeq] extends ParSeqBench[T, Coll] { +trait ParSeqViewBenches[T, Coll <: ParSeqView[T, ParSeq[T], CollSeq], CollSeq] extends ParSeqBenches[T, Coll] { +self => - object Reduce extends IterableBenchCompanion { + 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.foreach(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).foreach(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).foreach(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).foreach(operators.eachFun) + def runseqview = this.seqview.++(appended).foreach(operators.eachFun) + def companion = IterationA + } + + 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 ParSeqViewBench[T, Coll, CollSeq] { + 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 IterableBenchCompanion { + 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 ParSeqViewBench[T, Coll, CollSeq] { + extends SeqBench with SeqViewBench { def comparisonMap = collection.Map() def runseq = this.seqcoll.reduceLeft(operators.mediumreducer) def runpar = this.parcoll.reduce(operators.mediumreducer) @@ -168,7 +235,7 @@ trait ParSeqViewBench[T, Coll <: ParSeqView[T, ParSeq[T], CollSeq], CollSeq] ext } class ModifyThenReduce(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with ParSeqViewBench[T, Coll, CollSeq] { + extends SeqBench with SeqViewBench { val toadd = createSequential(size, parallelism) def comparisonMap = collection.Map() def runseq = { @@ -189,7 +256,7 @@ trait ParSeqViewBench[T, Coll <: ParSeqView[T, ParSeq[T], CollSeq], CollSeq] ext } class ModifyThenForce(val size: Int, val parallelism: Int, val runWhat: String) - extends SeqBench with ParSeqViewBench[T, Coll, CollSeq] { + 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) |