Skip to content

Instantly share code, notes, and snippets.

@Miuler
Forked from ryanlecompte/gist:5210745
Created March 21, 2013 05:36
Show Gist options
  • Save Miuler/5210893 to your computer and use it in GitHub Desktop.
Save Miuler/5210893 to your computer and use it in GitHub Desktop.
import scala.collection._
import com.twitter.util._
scala> val buffer = mutable.ArrayBuffer.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer += _ } }.inMillis)
17610
scala> var vector = immutable.Vector.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { vector :+= _ } }.inMillis)
7865
// do it again, just in case
scala> val buffer = mutable.ArrayBuffer.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer += _ } }.inMillis)
24742
// let's try a java.util.ArrayList
val buffer2 = new java.util.ArrayList[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer2.add(_) } }.inMillis)
7923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment