Last active
August 29, 2015 14:11
-
-
Save notyy/83accd051c09fbdf4257 to your computer and use it in GitHub Desktop.
stream memory
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
import scala.io.Source | |
def b2m(byte: Long): String = s"${byte / 1024 /1024}MB" | |
val runtime: Runtime = Runtime.getRuntime | |
println(s"max memory ${b2m(runtime.maxMemory())}MB") | |
println(s"total memory ${b2m(runtime.totalMemory())}") | |
println(s"init free memory ${b2m(runtime.freeMemory())}") | |
val file = Source.fromFile("/Users/twer/source/bigdata/data/new2.dat") | |
var size = 0 | |
//file.getLines().toStream.foreach(_ => size += 1) | |
//file.getLines().toList.foreach(_ => size += 1) | |
file.getLines().foreach(_ => size += 1) | |
println(s"data size: $size") | |
//println(s"data size: ${file.getLines().toList.size}") | |
//println(s"data size: ${file.getLines().size}") | |
//runtime.gc() | |
println(s"remain total memory ${b2m(runtime.totalMemory())}") | |
println(s"remain free memory ${b2m(runtime.freeMemory())}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment