Created
March 24, 2016 00:19
-
-
Save duese/ba6089bd2f8c87878c4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/510462/is-system-nanotime-completely-useless | |
import scala.collection.mutable | |
val numThreads = 10 | |
val numValuesPerThread = 10 | |
var threadResult = mutable.Map[Int, Seq[Long]]() | |
val threadList = for (currentThreadIndex <- 0 to numThreads) yield { | |
new Thread(new Runnable { | |
override def run(): Unit = { | |
threadResult(currentThreadIndex) = | |
(0 to numValuesPerThread).map { case _ => System.nanoTime } | |
} | |
}, s"thread-$currentThreadIndex") | |
} | |
threadList foreach { thread => thread.start() } | |
println(s"All threads started. (result size = ${threadResult.size})") | |
threadList foreach { thread => thread.join() } | |
println(s"All threads joined. (result size = ${threadResult.size})") | |
for (currentThreadIndex <- 0 to numThreads; | |
currentValueIndex <- 0 to numValuesPerThread) { | |
val list: Seq[Long] = threadResult(currentThreadIndex) | |
} | |
var l0 = List(1,2,3,4,8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ktoso/sbt-jmh