Skip to content

Instantly share code, notes, and snippets.

@dacr
Created January 25, 2013 14:05
Show Gist options
  • Save dacr/4634691 to your computer and use it in GitHub Desktop.
Save dacr/4634691 to your computer and use it in GitHub Desktop.
small test to check memory benefit of String substring change in Java 1.7.0_06
#!/bin/sh
exec scala -deprecation -nocompdaemon "$0" "$@"
!#
def usedMemoryInMo() = {
val rt= java.lang.Runtime.getRuntime
(rt.totalMemory - rt.freeMemory)/1024/1024
}
println(util.Properties.javaVersion)
val substrings = for(i <- 1 to 10000) yield {
val str="0123456789"*1024 // le motif répété 1024 fois
str.substring(str.size/2, str.size/2+10)
}
System.gc
Thread.sleep(1000)
println(usedMemoryInMo+"Mo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment