summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-06-18 18:09:12 +0200
committerAleksandar Prokopec <axel22@gmail.com>2012-06-18 18:36:41 +0200
commit6f5979f00118e19b1e3e143d366f2d6029a63466 (patch)
treea9eaabd660ca3f6a0853a60c8dfd2bc60dbb49fe
parent9a28ee1ffc085bc680c48b12ad632b9133adf020 (diff)
downloadscala-6f5979f00118e19b1e3e143d366f2d6029a63466.tar.gz
scala-6f5979f00118e19b1e3e143d366f2d6029a63466.tar.bz2
scala-6f5979f00118e19b1e3e143d366f2d6029a63466.zip
Use `ThreadLocalRandom` in `TrieMap.size`.
-rw-r--r--src/library/scala/collection/concurrent/TrieMap.scala6
-rw-r--r--test/benchmarking/ParCtrie-size.scala11
2 files changed, 12 insertions, 5 deletions
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala
index 08e9125bd8..2d8217551a 100644
--- a/src/library/scala/collection/concurrent/TrieMap.scala
+++ b/src/library/scala/collection/concurrent/TrieMap.scala
@@ -473,7 +473,11 @@ extends CNodeBase[K, V] {
private def computeSize(ct: TrieMap[K, V]): Int = {
var i = 0
var sz = 0
- val offset = math.abs(util.Random.nextInt()) % array.length
+ val offset =
+ if (array.length > 0)
+ //util.Random.nextInt(array.length) /* <-- benchmarks show that this causes observable contention */
+ scala.concurrent.forkjoin.ThreadLocalRandom.current.nextInt(0, array.length)
+ else 0
while (i < array.length) {
val pos = (i + offset) % array.length
array(pos) match {
diff --git a/test/benchmarking/ParCtrie-size.scala b/test/benchmarking/ParCtrie-size.scala
index 5a6191fb62..3f47dc23fd 100644
--- a/test/benchmarking/ParCtrie-size.scala
+++ b/test/benchmarking/ParCtrie-size.scala
@@ -2,16 +2,18 @@
-import collection.parallel.mutable.ParCtrie
+import collection.parallel.mutable.ParTrieMap
object Size extends testing.Benchmark {
val length = sys.props("length").toInt
val par = sys.props("par").toInt
- var parctrie = ParCtrie((0 until length) zip (0 until length): _*)
+ var parctrie = ParTrieMap((0 until length) zip (0 until length): _*)
- collection.parallel.ForkJoinTasks.defaultForkJoinPool.setParallelism(par)
+ //collection.parallel.ForkJoinTasks.defaultForkJoinPool.setParallelism(par)
+ val ts = new collection.parallel.ForkJoinTaskSupport(new concurrent.forkjoin.ForkJoinPool(par))
+ parctrie.tasksupport = ts
def run = {
parctrie.size
@@ -21,7 +23,8 @@ object Size extends testing.Benchmark {
override def tearDown() {
iteration += 1
- if (iteration % 4 == 0) parctrie = ParCtrie((0 until length) zip (0 until length): _*)
+ if (iteration % 4 == 0) parctrie = ParTrieMap((0 until length) zip (0 until length): _*)
+ parctrie.tasksupport = ts
}
}