Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immutable.Queue should override :+ using enqueue #8059

Closed
scabug opened this issue Dec 9, 2013 · 2 comments
Closed

immutable.Queue should override :+ using enqueue #8059

scabug opened this issue Dec 9, 2013 · 2 comments

Comments

@scabug
Copy link

@scabug scabug commented Dec 9, 2013

Kim Hansen reported on #scala that +: is two magnitudes slower than enqueue:

object QueuePerformance {
println("Test performance of Queue") //> Test performance of Queue
 
import scala.collection.immutable.Queue

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
}

The same thing should probably happen for +:.

@scabug
Copy link
Author

@scabug scabug commented Dec 9, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8059?orig=1
Reporter: @soc
Affected Versions: 2.10.3, 2.11.0-M7

@scabug
Copy link
Author

@scabug scabug commented Dec 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants