I am trying to find the memory usage of a Scala program I am even getting the result. I am referring the following code:
object Test {
def main(args: Array[String]): Unit = {
val mb = 1024*1024
val runtime = Runtime.getRuntime
println("\nMemory in MB")
println("** Used Memory: " + (runtime.totalMemory - runtime.freeMemory)/mb)
println("** Free Memory: " + runtime.freeMemory/mb)
println("** Total Memory: " + runtime.totalMemory/mb)
println("** Max Memory: " + runtime.maxMemory/mb)
}
}
Output is as follows:
Memory in MB -
** Used Memory: 2
** Free Memory: 28
** Total Memory: 31
** Max Memory: 228
However, how accurate is the result that this code is using 2MB memory? Is there a better way to do such bench-marking?