summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries
diff options
context:
space:
mode:
Diffstat (limited to 'test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries')
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Combine.scala66
-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.scala31
-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/hashtries/MultipleCombine.scala87
-rw-r--r--test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/ParallelHashTries.scala180
8 files changed, 0 insertions, 571 deletions
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Combine.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Combine.scala
deleted file mode 100644
index 96598840fd..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Combine.scala
+++ /dev/null
@@ -1,66 +0,0 @@
-package scala.collection.parallel.benchmarks
-package hashtries
-
-
-
-
-import collection.immutable.{HashMap => HashTrie}
-import collection.mutable.HashMap
-
-
-
-
-
-
-class Combine(val size: Int, val parallelism: Int, val runWhat: String) extends Bench with IntInit {
- var thattrie = new HashTrie[Int, Int]
- for (i <- size until 2 * size) thattrie += ((i, i))
- val thatmap = new HashMap[Int, Int]
- for (i <- size until 2 * size) thatmap += ((i, i))
-
- def runpar = throw new UnsupportedOperationException
- def runseq = runhashtrie
- def runhashtrie = {
- hashtrie merge thattrie
- // println
- // println("both tries: " + HashTrie.bothtries)
- // println("one trie, one item: " + HashTrie.onetrie)
- // println("both single: " + HashTrie.bothsingle)
- // System exit 1
- }
- def rundestructive = {
- hashtrie merge thattrie
- }
- def runappendtrie = hashtrie ++ thattrie
- def runhashmap = hashmap ++ thatmap
- def companion = Combine
- def comparisonMap = Map("hashtrie" -> runhashtrie _, "hashmap" -> runhashmap _, "destruct" -> rundestructive _, "appendtrie" -> runappendtrie _)
- override def reset = runWhat match {
- case "appendtrie" => initHashTrie
- case "destruct" => initHashTrie
- case _ => super.reset
- }
-}
-
-
-object Combine extends BenchCompanion {
- def collectionName = "HashTrie"
- def benchName = "combine";
- def apply(sz: Int, p: Int, what: String) = new Combine(sz, p, what)
- override def defaultSize = 5000
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala
deleted file mode 100644
index f65a349ec5..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Construct.scala
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index f53ea02e36..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Foreach.scala
+++ /dev/null
@@ -1,45 +0,0 @@
-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 = runhashtrie
- 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
deleted file mode 100644
index 79ebd0e98c..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/IntInit.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-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
- case "seq" => 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))
- }
-
-}
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala
deleted file mode 100644
index d27aa200b8..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Iterate.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-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
deleted file mode 100644
index 4ee8c17118..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/Lookup.scala
+++ /dev/null
@@ -1,57 +0,0 @@
-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/hashtries/MultipleCombine.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/MultipleCombine.scala
deleted file mode 100644
index c08d6b5cad..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/MultipleCombine.scala
+++ /dev/null
@@ -1,87 +0,0 @@
-package scala.collection.parallel.benchmarks
-package hashtries
-
-
-
-
-import collection.immutable.{HashMap => HashTrie}
-import collection.mutable.HashMap
-
-
-
-
-
-
-class MultipleCombine(val size: Int, val parallelism: Int, val runWhat: String) extends Bench with IntInit {
- var combines = 10
-
- var thattries = new Array[HashTrie[Int, Int]](combines)
- def initTries = for (r <- 0 until combines) {
- var thattrie = new HashTrie[Int, Int]
- for (i <- ((r + 1) * size) until ((r + 2) * size)) thattrie += ((i, i))
- thattries(r) = thattrie
- }
- initTries
-
- val thatmaps = new Array[HashMap[Int, Int]](10)
- def initMaps = for (r <- 0 until combines) {
- var thatmap = new HashMap[Int, Int]
- for (i <- ((r + 1) * size) until ((r + 2) * size)) thatmap += ((i, i))
- thatmaps(r) = thatmap
- }
- initMaps
-
- override def repetitionsPerRun = 25
- def runpar = throw new UnsupportedOperationException
- def runseq = runhashtrie
- def runhashtrie = {
- initHashTrie
- var trie = hashtrie
- for (r <- 0 until combines) trie = trie merge thattries(r)
- }
- def runappendtrie = {
- initHashTrie
- var trie = hashtrie
- for (r <- 0 until combines) trie = trie ++ thattries(r)
- }
- def runhashmap = {
- initHashMap
- var map = hashmap
- for (r <- 0 until combines) map = map ++ thatmaps(r)
- }
- def rundestructive = {
- initHashTrie
- var trie = hashtrie
- for (r <- 0 until combines) trie = trie merge thattries(r)
- }
- def companion = MultipleCombine
- def comparisonMap = Map("hashtrie" -> runhashtrie _, "hashmap" -> runhashmap _, "appendtrie" -> runappendtrie _, "destruct" -> rundestructive _)
- override def reset = runWhat match {
- case "appendtrie" => initHashTrie
- case "destruct" => initHashTrie
- case _ => super.reset
- }
-}
-
-
-object MultipleCombine extends BenchCompanion {
- def collectionName = "HashTrie"
- def benchName = "multi-combine";
- def apply(sz: Int, p: Int, what: String) = new MultipleCombine(sz, p, what)
- override def defaultSize = 5000
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/ParallelHashTries.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/ParallelHashTries.scala
deleted file mode 100644
index dc8804cf57..0000000000
--- a/test/benchmarks/src/scala/collection/parallel/benchmarks/hashtries/ParallelHashTries.scala
+++ /dev/null
@@ -1,180 +0,0 @@
-package scala.collection.parallel.benchmarks.hashtries
-
-
-
-
-import scala.collection.parallel.benchmarks.generic.StandardParIterableBenches
-import scala.collection.parallel.benchmarks.generic.Dummy
-import scala.collection.parallel.benchmarks.generic.Operators
-import scala.collection.parallel.immutable.ParHashMap
-
-
-
-
-
-trait ParHashTrieBenches[K, V] extends StandardParIterableBenches[(K, V), ParHashMap[K, V]] {
-
- def nameOfCollection = "immutable.ParHashMap"
- def comparisonMap = collection.Map()
- val forkJoinPool = new scala.concurrent.forkjoin.ForkJoinPool
-
- object Map2 extends IterableBenchCompanion {
- override def defaultSize = 5000
- override def comparisons = List("jhashtable", "hashtable")
- def benchName = "map2";
- def apply(sz: Int, p: Int, w: String) = new Map2(sz, p, w)
- }
-
- class Map2(val size: Int, val parallelism: Int, val runWhat: String)
- extends IterableBench {
- var result: Int = 0
- def comparisonMap = collection.Map("jhashtable" -> runjhashtable _, "hashtable" -> runhashtable _)
- def runseq = {
- val r = this.seqcoll.asInstanceOf[collection.immutable.HashMap[K, V]].map(operators.mapper2)
- result = r.size
- }
- def runpar = {
- result = this.parcoll.map(operators.mapper2).size
- }
- def runjhashtable = {
- val jumap = new java.util.HashMap[K, V]()
- val it = this.seqcoll.iterator
- while (it.hasNext) {
- val p = it.next
- jumap.put(p._1, p._2)
- }
- result = jumap.size
- }
- def runhashtable = {
- val smap = collection.mutable.HashMap[K, V]()
- val it = this.seqcoll.iterator
- while (it.hasNext) {
- val p = it.next
- smap.put(p._1, p._2)
- }
- result = smap.size
- }
- override def reset = runWhat match {
- case "jhashtable" => this.seqcoll = createSequential(size, parallelism)
- case "hashtable" => this.seqcoll = createSequential(size, parallelism)
- case _ => super.reset
- }
- def companion = Map2
- override def repetitionsPerRun = 50
- override def printResults {
- println("Size of last result: " + result)
- }
- }
-
- object Reduce2 extends IterableBenchCompanion {
- override def defaultSize = 50000
- override def comparisons = List("hashtable")
- def benchName = "reduce2";
- def apply(sz: Int, p: Int, w: String) = new Reduce2(sz, p, w)
- }
-
- class Reduce2(val size: Int, val parallelism: Int, val runWhat: String)
- extends IterableBench {
- private var ht: collection.mutable.HashMap[K, V] = _
- def comparisonMap = collection.Map("hashtable" -> runhashtable _)
- def runseq = this.seqcoll.reduceLeft(operators.reducer)
- def runpar = this.parcoll.reduce(operators.reducer)
- def runhashtable = ht.reduceLeft(operators.reducer)
- override def reset = runWhat match {
- case "hashtable" => ht = createHashTable(size)
- case _ => super.reset
- }
- def companion = Reduce2
- }
-
- def createHashTable(sz: Int): collection.mutable.HashMap[K, V]
-
-}
-
-
-
-
-
-object RefParHashTrieBenches extends ParHashTrieBenches[Dummy, Dummy] {
-
- type DPair = (Dummy, Dummy)
-
- object operators extends Operators[DPair] {
- def gcd(a: Int, b: Int): Int = {
- val result = if (b == 0) a else {
- gcd(b, a - b * (a / b))
- }
- result + 1000
- }
- def heavy(a: Int): Int = {
- var i = 0
- var sum = a
- while (i < 3000) {
- i += 1
- sum += a + i
- }
- sum
- }
- val foreachFun = (t: DPair) => {
- t
- ()
- }
- val reducer = (x: DPair, y: DPair) => {
- //y._2.num = x._2.in + y._2.in
- y
- }
- val mediumreducer = (x: DPair, y: DPair) => {
- y._2.num = gcd(x._2.in, y._2.in)
- y
- }
- val filterer = (p: DPair) => {
- p._1.num % 2 == 0
- }
- val mapper = (p: DPair) => {
- val a = p._1
- a.num = a.in % 2
- (a, p._2)
- }
- val flatmapper = (p: DPair) => {
- List(p, p, p, p, p)
- }
- override val mapper2 = (p: DPair) => {
- val a = 1 //heavy(p._1.in)
- (new Dummy(p._1.in * -2 + a), p._2)
- }
- val heavymapper = (p: DPair) => {
- val a = p._1
- var i = -100
- while (i < 0) {
- if (a.in < i) a.num += 1
- i += 1
- }
- (a, p._2)
- }
- val taker = (p: DPair) => true
- val eachFun: DPair => Unit = { dp =>
- dp._1.dummy
- }
- }
-
- def createSequential(sz: Int, p: Int) = {
- var ht = new collection.immutable.HashMap[Dummy, Dummy]
- for (i <- 0 until sz) ht += ((new Dummy(i), new Dummy(i)))
- ht
- }
-
- def createParallel(sz: Int, p: Int) = {
- var pht = new ParHashMap[Dummy, Dummy]
- for (i <- 0 until sz) pht += ((new Dummy(i), new Dummy(i)))
- forkJoinPool.setParallelism(p)
- collection.parallel.tasksupport.environment = forkJoinPool
- pht
- }
-
- def createHashTable(sz: Int) = {
- val hm = collection.mutable.HashMap[Dummy, Dummy]()
- for (i <- 0 until sz) hm.put(new Dummy(i), new Dummy(i))
- hm
- }
-
-}