Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.82 KB | None | 0 0
  1. object Test extends App {
  2.   @annotation.tailrec def test(list: List[Int] = Nil, i: Int = 0): Unit = {
  3.     println(i)
  4.     test(i :: list, i+1)
  5.   }
  6.   test()
  7. }
  8.  
  9. java -Xmx1G -Xms1G -classpath .:/usr/share/scala/lib/scala-library.jar Test
  10.  
  11. 21269711 // not an OutOfMemoryError, but sooo sloooow
  12.  
  13.  
  14. Adding to Vector is incredably slow, use VectorBuilder, you should get the same capacity:
  15.  
  16. import scala.collection.immutable.VectorBuilder
  17.  
  18. object TestVectorBuilder extends App {
  19.   val b = new VectorBuilder[Int]
  20.   for { i <- 1 to Int.MaxValue} {
  21.     println(i)
  22.     b += i
  23.   }
  24. }
  25.  
  26. java -Xmx1G -Xms1G -classpath .:/usr/share/scala/lib/scala-library.jar TestVectorBuilder
  27.  
  28. 47754251 // OutOfMemoryError
  29.  
  30. This works fine without OutOfMemoryError:
  31.  
  32. scala -J-Xmx1G -J-Xms1G -e '(1 to 45000000).toVector foreach println'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement