Last active
December 30, 2015 20:28
-
-
Save kimhanse/7880565 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 QueuePerformance { | |
println("Test performance of Queue") //> Test performance of Queue | |
import scala.collection.immutable.Queue | |
util.Properties.versionString //> res0: String = version 2.10.3 | |
System.getProperty("java.version") //> res1: String = 1.7.0_25 | |
def time[A](f: => A) = { | |
f | |
for (_ <- 1 to 3) { | |
val s = System.nanoTime | |
f | |
println("time: " + (System.nanoTime - s) / 1e6 + "ms") | |
} | |
} //> time: [A](f: => A)Unit | |
val count = 10000 //> count : Int = 10000 | |
time { | |
var q = Queue.empty[Int] | |
for (i <- 1 to count) { | |
q = q enqueue i | |
} | |
println(q.dequeue._1) | |
} //> 1 | |
//| 1 | |
//| time: 19.326757ms | |
//| 1 | |
//| time: 3.575115ms | |
//| 1 | |
//| time: 1.428872ms | |
time { | |
var q = Queue.empty[Int] | |
for (i <- 1 to count) { | |
q = q :+ i | |
} | |
println(q.dequeue._1) | |
} //> 1 | |
//| 1 | |
//| time: 576.121048ms | |
//| 1 | |
//| time: 511.96562ms | |
//| 1 | |
//| time: 582.245494ms | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment