Created
April 16, 2015 17:31
-
-
Save paul-lysak/59e54e3f811cc216bea8 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
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