Skip to content

Instantly share code, notes, and snippets.

@paul-lysak
Created April 16, 2015 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-lysak/59e54e3f811cc216bea8 to your computer and use it in GitHub Desktop.
Save paul-lysak/59e54e3f811cc216bea8 to your computer and use it in GitHub Desktop.
object Test {
def main(args: Array[String]): Unit = {
println("hi there")
val threads = 1 to 3 map {new MyRunner(_)}
// val threads = 1 to 1 map {new MyRunner(_)}
threads.foreach(_.start)
val ts1 = System.currentTimeMillis()
threads.foreach(_.join)
val ts2 = System.currentTimeMillis()
val td = ts2 - ts1
val tds = threads.map(_.td).sum
println("final values:")
MyEnum.values.foreach(v => println(v.toString))
println(s"total: wait= $td, time=$tds")
}
}
class MyRunner(tid: Int) extends Thread {
var td: Long = 0
override def run(): Unit = {
val v1 = MyEnum.V1
val ts1 = System.currentTimeMillis()
for(i <- 0 to 10000000) {
v1.toString()
}
val ts2 = System.currentTimeMillis()
td = ts2 - ts1
println(s"thread $tid time=$td")
}
}
object MyEnum extends Enumeration {
val V1, V2, V3, V4, V5 = Value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment